gpt4 book ai didi

javascript - 纯 JavaScript 替代 jQuery 的 .html()

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

以下代码用于 ajax 加载一个 div。

我遇到的唯一问题是 .html() 呈现 raw html,所以我认为用纯文本替换它可能是个好主意JS 替代方案,这样我的 View 就不会出现任何转义的原始 html。

我很想听听您对此的看法。

$(document).ready(function() {
$('.ajax_load').each(function(index, element) {
var url = $(element).data('remote-url')
if (url) {
$.get(url, function(responseText) {
$(element).html(responseText);
})
} else {
console.log("missing url for ajax!")
}
})
})

最佳答案

您可以使用 textContent :

The Node.textContent property represents the text content of a node and its descendants.

element.textContent = responseText;

关于javascript - 纯 JavaScript 替代 jQuery 的 .html(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36185153/

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