100字范文,内容丰富有趣,生活中的好帮手!
100字范文 > select下拉框默认选择

select下拉框默认选择

时间:2021-01-30 05:41:47

相关推荐

select下拉框默认选择

select标签构成的下拉框和jquery通过js构建的下拉框用法一样。例如:

html下拉框:

<select id="editState" class="combobox validatebox" name="dto.baseCode.state" style="width:135px"data-options="editable:false,required:true"> <option value="1">启用</option> <option value="0" selected>停用</option> </select>

js控制的下拉框:

<input id="editDisplayName" class="combobox" name="dto.baseCode.displayName" />

$('#editDisplayName').combobox({ url:$WEB_ROOT_PATH+'/basecode/baseCodeCtrl.htm?BLHMI=findBaseCode&dto.baseCode.codeSystem='+diseaseCategory,valueField:'id', textField:'text',disabled:true,onLoadSuccess:function(){$CommonUI.getComboBox('#editDisplayName').combobox("setText",row.displayName);$CommonUI.getComboBox('#editDisplayName').combobox("setValue",row.displayName);}});

两者的本质是相同的,但是,select标签创建的下拉框会默认选中第一个选项。而js控制的下拉框默认是不会选中任何选项的。

当然select标签的默认选项可以通过为option标签添加selected属性设置。

而js控制的下拉框可以通过$("id").combobox('setValue',value);设置初始值。

下拉框的默认值的获取方式:

$("id").next().children(":text").val()或者$("id").combobox("getValue").

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。