javascript - 在 'this' 上调用 jQuery $ 函数

标签 javascript jquery

在下面的代码中,为什么需要用$函数将'this'括起来?

var x = $('div');
x.click(function(){
    $(this).hide();
});

“this”不是指的是表达式 x,它本身就是一个 jQuery 对象吗?

最佳答案

this 的值将是表示被单击元素的 DOM 节点。 $(this) 将是一个包装该 DOM 节点的 jQuery 对象,并提供额外的函数,如 .show().append()、等等

关于javascript - 在 'this' 上调用 jQuery $ 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14963841/

相关文章:

javascript - 已修复 : Why is my dynamic SELECT not working in IE9?

javascript - D8 : Program type already present: android. support.v4.app.INotificationSideChannel$Stub$Proxy

javascript - 如何使用网络音频 api 测量压缩?

javascript - 在可扩展 Accordion 内显示 <div></div> - 不显示 <div> 内的内容

javascript - 使用javascript的可拖动DIV

javascript - jquery 变量到 $(jquery 变量),两者有什么区别

javascript - 为什么这个正则表达式替换在开头而不是在结尾删除符号?

javascript - 在真实脚本上尝试时 fiddle 不起作用

javascript - 通过单击外部来退出动态弹出窗口吗?

javascript - 通过 Date() 显示时间 : it is not being updated using setInterval()