我正在阅读一本关于 jQuery 的优秀书籍(Apress Pro jQuery),我对“this”的使用有点困惑。 例如我正在阅读以下代码:
<script type="text/javascript">
$(document).ready(function() {
var isResult = $('img').is(function(index) {
return this.getAttribute("src") == "rose.png";
});
console.log("Result: " + isResult);
});
</script>
我想知道在这种情况下“this”指的是哪个对象。 谢谢。
最佳答案
“this”上下文中的
this
是对 DOM img
元素的引用。
关于jquery - jQuery 代码中 'this' 的含义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10454914/