gpt4 book ai didi

javascript - .load() 等 Ajax 函数从 HTML 中去除注释。我怎样才能保留评论?

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:37:01 24 4
gpt4 key购买 nike

例如,$('#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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com