📜  javascript 转义 html - Javascript 代码示例

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

代码示例4
//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, "'");
}