我想使用 javascript 将 &
替换为 &
。这是我的示例代码.EmployeeCode
可以包含&。 EmployeeCode 是从 Datagrid 中选择的,它显示在“txtEmployeeCode”文本框中。但是,如果 EmployeeCode 包含任何 &
,那么它会在文本框中显示 &
。 &
如何从 EmployeeCode 中删除?谁能帮忙...
function closewin(EmployeeCode) {
opener.document.Form1.txtEmployeeCode.value = EmployeeCode;
this.close();
}
最佳答案
有了这个:
function unEntity(str){
return str.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
}
function closewin(EmployeeCode) {
opener.document.Form1.txtEmployeeCode.value = unEntity(EmployeeCode);
this.close();
}
可选 如果您使用的是 jQuery,这将解码任何 html 实体(不仅是 &
<
和 >
):
function unEntity(str){
return $("<textarea></textarea>").html(str).text();
}
干杯
关于javascript - 在 javascript 中将 & 替换为 &,将 <lt 替换为 < 并将 >gt 替换为 gt,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20964811/