js select下拉框数据绑定的几种方式
1.// ( " s e l e c t [ n a m e = ′ p a y s t a t u s ′ ] " ) . v a l ( " @ M o d e l . p a y s t a t u s " ) ; 注 : 根 据 ("select[name='paystatus']").val("@Model.paystatus"); 注:根据 ("select[name=′paystatus′]").val("@Model.paystatus");注:根据(“select[name=‘paystatus’]”)标签查询select对象并为其赋值;
2.//$("#paystatus option[value=’@Model.paystatus’]").attr(“selected”, true); //方法二
注:分解$("#ID option[value=’@Model.paystatus’]")查询select option值为@Model.paystatus的选项对象,使用attr()方法赋值selected属性为True;
3.$("#selectId").val(“value”);
4.var select =
document.getElement.get(“selectId”);
select.options[i].selected = true;
注意:
1.使用下拉框时,readonly属性无效,数据绑定后禁止使用disabled属性,否则无法将下拉框值传到后台;
$("#selectId").attr(“disabled”,“disabled”);
2.如果使用,在表单提交前移除:
function checkDisable() {
KaTeX parse error: Expected '}', got 'EOF' at end of input: … if (parseInt((this).val()) != -1) {
$(this).attr(“disabled”, false);
}
});
return true;
参考文章 :