Ajax的功能,如.load()剥离出的HTML注释。我怎样才能保持评论? [英] Ajax functions like .load() strip out comments from the HTML. How can I keep the comments?

查看:114
本文介绍了Ajax的功能,如.load()剥离出的HTML注释。我怎样才能保持评论?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如, $('#一些-DIV').load('http://foo.bar#内容)将检索#内容 http://foo.bar 但所有HTML <! - 评论 - >

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

我如何可以检索#内容内容的包括的任何意见?

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

推荐答案

jQuery的手动

jQuery使用浏览器的 .innerHTML 属性分析检索文档,并将其插入到当前文档。在这个过程中,浏览器通常过滤从文档元素,如&LT; HTML&GT; &LT;冠军&GT; &LT; HEAD&GT; 元素。其结果,元件检索 .load()可能不完全一样的,如果该文件是由浏览器直接检索。

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.

所以,你应该使用 $。获得()检索HTML而不是 $。fn.load()

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

这篇关于Ajax的功能,如.load()剥离出的HTML注释。我怎样才能保持评论?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆