Using jQuery set the disabled property and remove the disabled attribute

The difference between the disabled and readOnly form:
Readonly only for input (text / password) and textarea effective, and valid for all disabled form elements, including select, radio, checkbox, button and so on.
But form elements in the use of the disabled, when we submit a form with POST or GET way, then the value of this element will not be passed out, and readonly The value is passed out (this happens we will be in a textarea form element is set to disabled or readonly, but it can be used submitbutton).

js Operation:
copy the code code is as follows:

function disableElement(element,val){
    document.getElementById(element).disabled=val;
}

 

 

jQuery operation:
copy the code code is as follows:

//两种方法设置disabled属性
$('#areaSelect').attr("disabled",true);
$('#areaSelect').attr("disabled","disabled");
//三种方法移除disabled属性
$('#areaSelect').attr("disabled",false);
$('#areaSelect').removeAttr("disabled");
$('#areaSelect').attr("disabled","");

 

 

Get s: textfield, disabled and set its properties:
copy the code code is as follows:

function disableTextfieldofAccountDiv(element,val) {
    $(element).find(":textfield").attr('disabled',val);
}

 

 
 

 

reference:

https://www.imooc.com/article/14003

 

 

Guess you like

Origin www.cnblogs.com/poterliu/p/11725807.html