jquery设置元素的readonly和disabled

jquery-logo

Jquery的api中提供了对元素应用disabled和readonly属性的方法,在这里记录下。如下:
1.readonly
$(‘input’).attr(“readonly","readonly")//将input元素设置为readonly
$(‘input’).removeAttr(“readonly");//去除input元素的readonly属性

if($(‘input’).attr(“readonly")==true)//判断input元素是否已经设置了readonly属性

 

对于为元素设置readonly属性和取消readonly属性的方法还有如下两种:
$(‘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属性

 

对于为元素设置disabled属性和取消disabled属性的方法还有如下两种:
$(‘input’).attr(“disabled",true)//将input元素设置为disabled
$(‘input’).attr(“disabled",false)//去除input元素的disabled属性

 

$(‘input’).attr(“disabled","disabled")//将input元素设置为disabled
$(‘input’).attr(“disabled","")//去除input元素的disabled属性

$(“#descrip").prop(“readonly",true);

$(“#descrip").prop(“readonly",false);

Set something readonly:
$(“#someId").attr(‘readonly’, ‘readonly’);
Remove readonly:

$(“#someId").removeAttr(‘readonly’);

For enabling readonly:

$(“#descrip").attr(“readonly","true");
For disabling readonly

$(“#descrip").attr(“readonly","");

  本文出處
    www.cnblogs.com

Be the first to comment on "jquery设置元素的readonly和disabled"

Leave a comment

Your email address will not be published.


*