jQuery设置input的disable属性,prop和attr的区别


<form:radiobuttons path="isInsuredCasualty" class="input-xxlarge" items="${fns:getDictList('yes_no')}" itemLabel="label" itemValue="value" htmlEscape="false"/>

//获取input的disable属性 true false
$("input[name='isInsuredCasualty']").is(":disabled")

//判断input是否选中
$("input[name='isInsuredCasualty']").is(":checked")

//设置input的disable为true 不能选
$('input:radio[name="isInsuredCasualty"]').prop("disabled",true);

//移除input的选中状态
$('input:radio[name="isInsuredCasualty"]:checked').removeAttr("checked");

prop与attr

prop()是 jQuery 1.6 开始新增了一个方法,官方建议具有 truefalse 两个属性的属性,如 checked, selected 或者 disabled 使用prop(),其他的使用 attr()。

可以将attribute理解为“特性”,property理解为为“属性”从而来区分俩者的差异。

例如设置元素的disabled属性:
$('input:radio[name="isInsuredCasualty"]').prop("disabled",true);

设置元素的点击事件 用attr
$('#buttionId').attr("onclick","");

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM