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