像.load()这样的Ajax函数会从HTML中删除注释。我该如何保留评论?

时间:2022-11-24 23:00:18

For example, $('#some-div').load('http://foo.bar #content') will retrieve #content from http://foo.bar but with all HTML <!--comments--> stripped.

例如,$('#some-div')。load('http://foo.bar #content')将从http://foo.bar检索#content,但所有HTML 剥离。

How can I retrieve the contents of #content including any comments?

如何检索#content的内容,包括任何注释?

1 个解决方案

#1


1  

From the jQuery manual:

从jQuery手册:

jQuery uses the browser's .innerHTML property to parse the retrieved document and insert it into the current document. During this process, browsers often filter elements from the document such as <html>, <title>, or <head> elements. As a result, the elements retrieved by .load() may not be exactly the same as if the document were retrieved directly by the browser.

jQuery使用浏览器的.innerHTML属性来解析检索到的文档并将其插入到当前文档中。在此过程中,浏览器通常会过滤文档中的元素,例如,

元素。因此,.load()检索的元素可能与浏览器直接检索文档的元素不完全相同。

So you should use $.get() to retrieve the HTML instead of $.fn.load()

所以你应该使用$ .get()来检索HTML而不是$ .fn.load()

#1


1  

From the jQuery manual:

从jQuery手册:

jQuery uses the browser's .innerHTML property to parse the retrieved document and insert it into the current document. During this process, browsers often filter elements from the document such as <html>, <title>, or <head> elements. As a result, the elements retrieved by .load() may not be exactly the same as if the document were retrieved directly by the browser.

jQuery使用浏览器的.innerHTML属性来解析检索到的文档并将其插入到当前文档中。在此过程中,浏览器通常会过滤文档中的元素,例如,

元素。因此,.load()检索的元素可能与浏览器直接检索文档的元素不完全相同。

So you should use $.get() to retrieve the HTML instead of $.fn.load()

所以你应该使用$ .get()来检索HTML而不是$ .fn.load()