📜  jquery 转义 html 字符串 - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:03:49.543000             🧑  作者: Mango

代码示例2
//escaping HTML with jquery
var dangerousHTML = "";
$("#myElementID").text(dangerousHTML); //.text() function will escape and display text


//Alternatively, here is plain Javascript escape function
function escapeHtml(str) {
    return str.replace(/&/g, "&").replace(//g, ">").replace(/"/g, """).replace(/'/g, "'");
}