Javascript 将 jquery 元素转换为 html 元素
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7114780/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Convert jquery element to html element
提问by Freesn?w
I have a jQuery element but I have to send it to a function that only accepts HTML elements. How can I convert the jQuery element to an HTML element?
我有一个 jQuery 元素,但我必须将它发送到一个只接受 HTML 元素的函数。如何将 jQuery 元素转换为 HTML 元素?
回答by jtbandes
Try myJQueryElement.get(0)
or myJQueryElement[0]
. (get()
is most useful when you need negative indices, for example, as described in the documentation for get()
.)
尝试myJQueryElement.get(0)
或myJQueryElement[0]
。(get()
当您需要负索引时最有用,例如,如文档中所述get()
。)
回答by Dennis
$("#foo")[0]
will get you an HTML element. Using brackets is a tiny bit faster than using .get()
but not something you'll likely notice unless you are doing it millions of times.
$("#foo")[0]
会给你一个 HTML 元素。使用方括号比使用要快一点,.get()
但除非您这样做了数百万次,否则您可能不会注意到。