为什么我用的时候不能用
$('.pc-nav>li').map((x)=>$(x).text())
获取 innerText 而
$('.pc-nav>li').map(function(){return $(this).text()})
还好吗?
最佳答案
因为 x
不是元素,而是它在集合中的位置(索引)。采用第二个参数(您想要的实际元素):
$('.pc-nav>li').map((pos, el) => $(el).text())
下次,检查 the docs首先...
关于javascript - 使用 jQuery map 函数时出现箭头函数错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49493490/