弹出窗口选择一个类别名,名称是有单引号的,然后关闭这个窗口,把这个名称赋给父页,并显示,这时有错误发生,如何解决
Response.Write("<script>window.opener.document.getElementById('Tabs_Panel1_TextBoxCategoryID').value='" + CategoryID.ToString() + "';window.opener.document.getElementById('Tabs_Panel1_TextBoxSelectCategoryName').value='" + CategoryName + "';window.opener.document.getElementById('Tabs_Panel1_TextBoxCategoryName').value='" + CategoryName + "';window.close();</script>");
如果CategoryName有单引号,就会出错,如何解决这个问题?
------解决方案--------------------
Response.Write(" <script>window.opener.document.getElementById('Tabs_Panel1_TextBoxCategoryID').value='" + CategoryID.ToString() + "';
var categoryName=\""+CategoryName+"\";
window.opener.document.getElementById('Tabs_Panel1_TextBoxSelectCategoryName').value=categoryName+ "';window.opener.document.getElementById('Tabs_Panel1_TextBoxCategoryName').value=categoryName;window.close(); </script>");
这样定义一个javascript的变量,用双引号分隔,试试