本文介绍了< link>的Jquery选择器< head>中的元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们使用jQuery来解析一些HTML。然后我需要遍历该文档并找到一些元素。在我需要找到的元素中,有< link> 元素。

We use jQuery to parse some HTML. I then need to traverse that document and find some elements. Among the elements I need to find, there are the <link> elements.

提取所有< a> 元素:

$(string).find("a")

但这不能解压缩< link> 元素:

$(string).find("link")

string 参数是html内容收到请求)。

The string parameter is the html content (e.g. received on a request).

任何想法为什么? (我想, find 只适用于< body> 元素)。另外,关于如何实际提取这些< link> 元素的任何想法?

Any idea why? (I guess that the find only applies to the <body> elements). Also, any idea on how to actually extract these <link> elements?

推荐答案

$(string)(这是函数 jQuery(html,[ownerDocument])):

当传入复杂的HTML时,一些
浏览器可能不会生成
完全复制提供的HTML源代码
的DOM。如上所述,我们使用
浏览器的.innerHTML属性来解析传递的HTML中的
,并将其插入到
当前文档中。 在此过程中,
某些浏览器会过滤掉某些
元素,例如< html> < title> ;
< head> 元素。
因此,插入的
元素可能不是
代表原始字符串
传递。

尽量不要使用jQuery来操纵整个 HTML文件。

Try not to use jQuery to manipulate entire HTML documents.

请注意,在独立的HTML代码段中,请注意链接节点。

Note, in particular, that a link node in a standalone snippet of HTML can be "found" just fine.

这篇关于&lt; link&gt;的Jquery选择器&lt; head&gt;中的元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 12:19
查看更多