$.ajax({
url:'{:U('xxx/xxx')}',
type:"post",
data:{id:data.id},
dataType:"json",
success:function(rs){
$("#fineid").val(rs.id);
$("#select_id option[value='2']").attr("selected", true);
form.render('select');
$("#fkmoney").val(rs.fkmoney);
}
});
再append之后添加form.render('select');
jQuery获取Select元素,并选择的Text和Value:
1. $("#select_id").change(function(){//code...}); //为Select添加事件,当选择其中一项时触发
2. var checkText=$("#select_id").find("option:selected").text(); //获取Select选择的Text
3. var checkValue=$("#select_id").val(); //获取Select选择的Value
4. var checkIndex=$("#select_id ").get(0).selectedIndex; //获取Select选择的索引值
5. var maxIndex=$("#select_id option:last").attr("index"); //获取Select最

本文介绍了如何解决layui动态添加select option不显示的问题,包括jQuery操作select的常见方法,如获取和设置选中项的text、value和索引,以及添加、删除option等。同时展示了在有层级关系的select中,如何根据选择动态更新下级选项。
最低0.47元/天 解锁文章
120

被折叠的 条评论
为什么被折叠?



