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

标签 jquery jquery-selectors

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

相关文章:

javascript - 如何使用当前数据提交 jQuery 表单的克隆?

jQuery 选择器查找行中除给定索引之外的所有单元格

jquery-ui - 使用jquery动态创建具有递增id的div

javascript - 如何从 txt 文档中的列表中获取文本字符串?

javascript - 插入时动态创建的 DOM 节点的处理程序

javascript - jquery .html() append 后绑定(bind)不起作用

jquery - 突出显示所选页码的有效方法是什么?

javascript - 此上下文与筛选器上的属性选择器

javascript - 如何使用jquery获取一页中所有<li>标签的内容

jquery - ScrollLeft 不运行