有时我会看到类似 $('<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/