我怎麼能有這樣的事情:添加事件一次
<input class="myClass" id="a" type="checkbox" other="x"/>
<input class="myClass" id="b" type="checkbox" other="x"/>
<input class="myClass" id="c" type="checkbox" other="x"/>
<input class="myClass" id="d" type="checkbox" other="y"/>
<input class="myClass" id="e" type="checkbox" other="z"/>
我可以檢索元素A至E,增加一個點擊事件,我想在元素上添加事件定義中attribut other
(x,y和z)。
我該怎麼做?
我嘗試:
$(".myClass").each(function() {
$("#" + $(this).attr("other")).click(function() {
...
});
});
但三個要素有other="x"
因此事件是x上添加三個時間,我想只有一個。
我與「關上」的解決方案去了。謝謝 – Snote