我想更换&到&使用JavaScript.这是我的示例代码.EmployeeCode可以包含&.EmployeeCode是从Datagrid中选择的,它显示在"txtEmployeeCode"文本框中.但是如果EmployeeCode包含any,&那么它会显示&在文本框中.如何&从EmployeeCode中删除?谁能帮忙......
function closewin(EmployeeCode) {
opener.document.Form1.txtEmployeeCode.value = EmployeeCode;
this.close();
}
Run Code Online (Sandbox Code Playgroud)
有了这个:
function unEntity(str){
return str.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
}
function closewin(EmployeeCode) {
opener.document.Form1.txtEmployeeCode.value = unEntity(EmployeeCode);
this.close();
}
Run Code Online (Sandbox Code Playgroud)
可选如果您使用的是jQuery,这将解码任何html实体(不仅仅是& <和>):
function unEntity(str){
return $("<textarea></textarea>").html(str).text();
}
Run Code Online (Sandbox Code Playgroud)
干杯
| 归档时间: |
|
| 查看次数: |
18142 次 |
| 最近记录: |