相关疑难解决方法(0)

'$(this)'和'this'之间有什么区别?

我目前正在学习本教程:jQuery入门

对于以下两个示例:

$("#orderedlist").find("li").each(function (i) {
    $(this).append(" BAM! " + i);
});
$("#reset").click(function () {
    $("form").each(function () {
        this.reset();
    });
});
Run Code Online (Sandbox Code Playgroud)

请注意,在第一个示例中,我们使用$(this)在每个li元素中附加一些文本.在第二个示例中,我们this在重置表单时直接使用.

$(this)似乎比使用频率更高this.

我的猜测是在第一个例子中,$()将每个li元素转换为理解append()函数的jQuery对象,而在第二个示例中reset()可以直接在表单上调用.

基本上我们需要$()特殊的jQuery功能.

它是否正确?

javascript jquery this

560
推荐指数
6
解决办法
58万
查看次数

$(this)和jquery之间的区别

使用$(this)与此相比有什么根本区别

$('.viewComments').click(function(ev){
    //returns the desired value
    alert(this.getAttribute('id'));

    //Gives an error sayin function is not defined 
    alert($(this).getAttribute('id'));

    //returns the desired value
    alert($(this).attr('id'));
});
Run Code Online (Sandbox Code Playgroud)

我认为"$(this)"将包含"this"具有的所有功能以及更多..但似乎并非如此.

那么究竟是什么(这个)?和

我在使用它时知道哪些功能可用吗?(我知道我可以通过萤火虫来获取它们.但我想知道是否有其他方式 - 某些文档可能是)

jquery this

65
推荐指数
2
解决办法
2万
查看次数

标签 统计

jquery ×2

this ×2

javascript ×1