JavaScript js dynamically add and remove disabled and style attributes

1. js dynamic addition and removal of the disabled property

js operation:

function disableTest(element,val){
    document.getElementById(element).disabled=val;
}
 
document.getElementById("uid").disabled="";

 jQuery operate:

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

Get s: textfield, disabled and set its properties:

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

2. js dynamic display and hide style

function changefixe(frm,str){
	if(str=="0"){
		document.getElementById("uid").style.display="block";//显示
		document.getElementById("uid").disabled="true";//残废disabled
	}else{
		document.getElementById("uid").style.display="none";//隐藏
		document.getElementById("uid").disabled="";//去除disabled
	}
}

 Note: The disabled have the same function and there is readOnly,

The difference is:

       Readonly (Read-only property): only for input (text / password) and textarea effective.

       disabled (disability is a form element): valid for all form elements, including select, radio, checkbox, button and so on.

But after using the form elements 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).

Published 79 original articles · won praise 89 · views 20000 +

Guess you like

Origin blog.csdn.net/qq_39141486/article/details/103747128