有個小需求是根據號碼查詢該用戶信息,把歷史信息自動帶到頁面上,在自動加載radio 框的時候卻出現了問題,第一次可以正常加載,第二次之后就不能正常加載了,
之前的寫法是:
$("input[name='patientSex'][value="+list[j].patientSex+"]").attr("checked",true);
由於第二次不能自動選中,就想辦法,查資料,最后把attr 換成prop 就可以正常加載了。
$("input[name='patientSex'][value="+list[j].patientSex+"]").prop("checked",true);
清空選擇項:
$('input[type=radio][name="patientSex"]:checked').attr("checked", false);
具有 true 和 false 兩個屬性,如 checked, selected 或者 disabled 使用prop(),其他的使用 attr()