/* 1 */
$("div").click(function(e) {
alert(".click() called on '" + e.currentTarget.id + "'");
});
/* 2
$("div").each(function(){
$(this).click(function(e) {
alert(".click() called on '" + e.currentTarget.id + "'");
});
});
*/
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div id="target 1">
The Target One
</div>
<div id="other 2">
The Target TWO
</div>
是兩個功能1
和2
之間的區別是什麼,知道結果是一樣的嗎?!...
除了不太清晰並且手動執行某些操作之外沒有任何區別jQuery可以爲您做的事情。 –
沒有區別。在示例2中的每個都是多餘的 –
所以我可以寫第一個版本沒有功能限制/差異與第二個 – Serge