是否可以将 jquery '$(this)' 反转为 javascript 'this'?
如何做到这一点?
最佳答案
jQuery 基于集合,允许您使用索引器符号 ([]
) 或 get
访问该集合的元素。方法。
所以如果你有 jQuery 集:
var set = $(this);
...您可以通过 set[0]
到 set[set.length - 1]
以及通过 set.get(0) 访问其元素
到 set.get(set.length - 1)
(get
还支持从末尾开始索引的负索引)。
对于 $(this)
,当然,您根本不需要使用 $()
- 只需使用 this
直接。每当您有原始 DOM 引用时,无论是 this
还是 event.target
或者其他什么,都是如此。
关于javascript - 将 '$(this)' jquery 转为 javascript 'this',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32971477/