我使用 JQuery 在 html 元素中设置文本
$('#xmlTextArea').text(prepareXML(response))
我想替换所有<
和 >
与 >
和 <
当我使用 prettify Lib 时,它无法识别实体。我这样替换它:
function prepareXML(req){
str = req.replace(/</g,"<")
str = str.replace(/>/g,">")
console.log(str)
return str
}
但现在它打印字符串 >
而不是标志 >
.所以总而言之,我希望输出看起来一样,但是蜂鸣 >
在引擎盖下
最佳答案
text()
方法内部执行相同的操作,因此无需调用 prepareXML
方法。
$('#xmlTextArea').text(response)
或者使用
html()
方法。
$('#xmlTextArea').html(prepareXML(response))
关于javascript - HTML 打印 </> 而不是 </>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45049543/