gpt4 book ai didi

jquery - jQuery 尖括号选择器看起来是什么,比如 $ ('' )?

转载 作者:行者123 更新时间:2023-12-03 22:31:25 24 4
gpt4 key购买 nike

有时我会看到类似 $('<img/>') 的结构。怎么样$('<img/>')不同于$('img')我在哪里可以阅读更多相关内容?

我尝试查看 jQuery Selectors但没有发现任何与此格式相关的内容。

最佳答案

当传递一个看起来像 HTML 的字符串时,jQuery 函数会被重载以构造新的 jQuery 元素。来自 docs :

If a string is passed as the parameter to $(), jQuery examines the string to see if it looks like HTML (i.e., it starts with <tag ... >). If not, the string is interpreted as a selector expression, as explained above. But if the string appears to be an HTML snippet, jQuery attempts to create new DOM elements as described by the HTML. Then a jQuery object is created and returned that refers to these elements.

关于jquery - jQuery 尖括号选择器看起来是什么,比如 $ ('<img/>' )?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15951412/

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