Home > Article > Web Front-end > jquery sets/cancels readonly and disabled attributes for elements
Recommended tutorial: jq tutorial
1.readonly
$('input').attr("readonly","readonly")//将input元素设置为readonly $('input').removeAttr("readonly");//去除input元素的readonly属性 if($('input').attr("readonly")==true)//判断input元素是否已经设置了readonly属性
There are two other ways to set the readonly attribute and cancel the readonly attribute for an element as follows:
$('input').attr("readonly",true)//将input元素设置为readonly $('input').attr("readonly",false)//去除input元素的readonly属性
$('input').attr("readonly","readonly")//将input元素设置为readonly $('input').attr("readonly","")//去除input元素的readonly属性
2.disabled
$('input').attr("disabled","disabled")//将input元素设置为disabled $('input').removeAttr("disabled");//去除input元素的disabled属性 if($('input').attr("disabled")==true)//判断input元素是否已经设置了disabled属性
There are two other ways to set the disabled attribute and cancel the disabled attribute for an element:
$('input').attr("disabled",true)//将input元素设置为disabled $('input').attr("disabled",false)//去除input元素的disabled属性
$('input').attr("disabled","disabled")//将input元素设置为disabled $('input').attr("disabled","")//去除input元素的disabled属性
For more programming-related knowledge, please visit: Programming Video ! !
The above is the detailed content of jquery sets/cancels readonly and disabled attributes for elements. For more information, please follow other related articles on the PHP Chinese website!