例如,$('#some-div').load('http://foo.bar #content')
将检索 #content
来自 http://foo.bar但所有 HTML <!--comments-->
剥离。
如何检索 #content
的内容包括任何评论?
最佳答案
来自jQuery manual :
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.
所以你应该使用$.get()
检索 HTML 而不是 $.fn.load()
关于javascript - .load() 等 Ajax 函数从 HTML 中去除注释。我怎样才能保留评论?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5231351/