javascript - jQuery '$(this)'

标签 javascript jquery

为什么以及何时使用 $(this) 而不是 this

最佳答案

当您位于 DOM 对象(或任何其他与此相关的对象)的范围内时,您可以使用 this

例如:

$('a').click(function(){
     var href = $(this).prop('href'); //refers to to this a tags href
     var href1 = this.href; //ALSO refers to to this a tags href
})

关于javascript - jQuery '$(this)',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5911690/

相关文章:

javascript - Bootstrap 行导致 FullPageJS 的宽度和高度错误

javascript - 如何在sencha extjs窗口中获取iframe?

javascript - Angularjs 长轮询

javascript - 禁用 chop listview标题jquery mobile的长文本(单个单词)

javascript - 用css3实现Windows 8 Tile "Click"动画

Javascript "Permission Denied"IE.x 中的错误

javascript - 如何使用 React 库将数据导出到 Excel

javascript - Ajax选择并自动加载数据

javascript - 启动图像 div

jquery - 在 BlackNegative 上看到的效果