$("#x").removeAttr("checked").removeAttr("unchecked").attr("foo","bar");
結果在這個網站輸入:
<input type="checkbox" id="x" foo="bar">
然而這樣的:
$("#x").removeAttr("checked").removeAttr("unchecked").attr("checked","true");
結果在此:
<input type="checkbox" id="x" checked="checked">
這是怎麼回事?儘管檢查=「檢查」屬性,該複選框仍然固執地未選中。
切換HTML輸入的checked屬性的最佳方式是什麼?
是啊,偉大的答案 – Starkers
感謝@Starkers隊友,很高興幫助:) –
沒問題! :D – Starkers