"-6ren"> "-我有一个文本区域。在其点击事件上。我将其插入数据库中,然后将其显示为元素列表中的第一个元素。问题是。如果我输入""在textarea中,jquery无法正确显示。它显示为空。代码是 var note -6ren">
gpt4 book ai didi

javascript - Jquery 转义 "<" ">"

转载 作者:行者123 更新时间:2023-11-28 12:29:33 28 4
gpt4 key购买 nike

我有一个文本区域。在其点击事件上。我将其插入数据库中,然后将其显示为元素列表中的第一个元素。问题是。如果我输入"<afasd>"在textarea中,jquery无法正确显示。它显示为空。代码是

var note = $.trim( $('#rep_notes_add_notes').val());
if(note == "")
return false;
$.ajax({
url: 'include/tre.ajax.php',
type: 'POST',
data: {
action: 'insert',
note: note
},
dataType: 'json',
success: function(data) {
jQuery("#rep_notes_add_notes").val('');
jQuery(".no_notes").remove();
*$(".notes:eq(0)").before('<div class="notes">'+note+'<div class="note-added"> Added by '+user +'<span> on </span>'+data.update_time+'</div></div>');*
}
});

标记为*的行找到notes div,然后在其前面插入一个元素以显示新输入的文本。

有人可以帮我解决这个问题吗?

最佳答案

它不显示它,因为它认为 <afasd>是标签,不是文本。您需要更改 <&lt;来显示它。

var str = "<afasd>";
var escaped = str.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;");

关于javascript - Jquery 转义 "<" ">",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23501548/

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