我在讀http://docs.jquery.com/Tutorials:Getting_Started_with_jQuery。並且在這兩個代碼段中使用了this
。
$(document).ready(function() {
$("#orderedlist").find("li").each(function(i) {
$(this).append(" BAM! " + i);
});
});
$(document).ready(function() {
// use this to reset several forms at once
$("#reset").click(function() {
$("form").each(function() {
this.reset();
});
});
});
時候我們需要$(this)
和this
?他們之間有什麼區別?提前致謝。
可能的重複[有什麼區別「this」,「$ this」和「$(this)」?](http://stackoverflow.com/questions/3889570/what-is-the-difference-在這個這個和這個之間) – user113716
@patrick:我不認爲它是重複的。值得回答的是,爲什麼在這個特定代碼的一部分中需要'$(this)',而在另一部分中需要'this'。 – Blazemonger
@ mblase75:呃,我想我不同意。這個答案,加上本教程已經解釋的內容,使其成爲重複。閱讀另一個問題的答案應該可以解決這個問題。從教程:*「請注意,在'.each()'函數中,'this'指的是實際的元素。」* – user113716