gpt4 book ai didi

javascript - 如何从 $(this) jQuery 对象中获取 this DOM 对象?

转载 作者:行者123 更新时间:2023-11-30 08:01:33 25 4
gpt4 key购买 nike

我有一个函数,将 jQuery 对象作为参数传递给该函数。请参见下面的代码。

$('selector').click(function() {
// $(this) is the jquery object for the DOM on which I clicked.
test($(this));
});
function test(jqobj) {
// Here from jqobj, I want to get back the native javascript object (I mean the this)
}

最佳答案

jqobj 参数是一个 DOM 元素数组,因此您可以使用

     jqobj[0] 

但是测试数组的大小,如果它不是空的

     jqobj.length > 0

关于javascript - 如何从 $(this) jQuery 对象中获取 this DOM 对象?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26905573/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com