且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

通过ajax将DIV内容加载为HTML

更新时间:2023-12-05 08:13:10

你应该使用 $(this).html(newtext)而不是 $(this).text(newtext)

他们完全不同。 .text() 将逃脱 您的HTML并将其插入为简单的文本。或者正如文档所述:

They are quite different. .text() will "escape" your HTML and insert it as simply text. Or as the documentation states:


我们需要知道这个方法会转义为
提供的字符串,这样它就会在HTML中正确呈现。为此,它调用
DOM方法.createTextNode(),不会将字符串解释为
HTML。

We need to be aware that this method escapes the string provided as necessary so that it will render correctly in HTML. To do so, it calls the DOM method .createTextNode(), does not interpret the string as HTML.

你应该首先阅读文档。

如果你已经在使用jQuery,你可以使用它的 AJAX方法,让您的生活更轻松。

If you are already using jQuery, you could use it's AJAX methods which make your life much easier.