在jQuery中使用选择器找到节点后在箭头函数中使用$(this)会被定位到整个页面
$('.class').(()=>{console.log($(this))})
===>window
如果想使用$(this)来定位选定的元素应使用function
$('.class').(function(){console.log($(this))})
===>.class
在jQuery中使用选择器找到节点后在箭头函数中使用$(this)会被定位到整个页面
$('.class').(()=>{console.log($(this))})
===>window
如果想使用$(this)来定位选定的元素应使用function
$('.class').(function(){console.log($(this))})
===>.class
本文标题:jQuery中的箭头函数中的$(this)问题
本文链接:https://www.haomeiwen.com/subject/ikvugdtx.html
网友评论