前段時間,做了一個前端頁面用到了jquery來來添加或者刪除input和select控件的disabled屬性,具體總結如下:
1.以下二種方法是可以為input添加disabled屬性的方法:
//兩種方法設置disabled屬性
$('#selectId').attr("disabled",true);
$('#selectId').attr("disabled","disabled");
2.以下三種方法是移除(去除)掉input的disabled屬性的方法:
//三種方法移除disabled屬性
$('#selectId').attr("disabled",false);
$('#selectId').removeAttr("disabled");
$('#selectId').attr("disabled","");
3.移除或者刪除所有input和select控件的disabled屬性:
//移除所有select控件的disabled屬性
$("select").each(function () {
$(this).attr("disabled","");
});
//移除所有input控件的disabled屬性:
$("input").attr("disabled","");