有一种方法可以将 html 文本作为参数传递给 javascript 函数:只需在 html 标记中替换所有特定字符,然后再将其传递给 javascript 函数。稍后在 javascript 中,您只需将所有特定字符恢复正常即可。诀窍是让 javascript 只识别那些它除外的字符。
例子:
[[C#]]
string urlString = "http://localhost:8698/DotNetNuke_Community_06.02.01_Install/Default.aspx?TabID=157&categoryId=92&newCategoryId=92";
urlString = urlString.Replace("<", "µ");
urlString = urlString.Replace(">", "Ħ");
urlString = urlString.Replace("&", "€");
urlString = urlString.Replace(":", "¥");
urlString = urlString.Replace("=", "¬");
urlString = urlString.Replace("/", "ä");
urlString = urlString.Replace("?", "¿");
urlString = urlString.Replace("'", "ʅ");
function(urlString);
[[Javascript]]
function(urlString){
urlString = urlString.replace(/µ/g, "<");
urlString = urlString.replace(/Ħ/g, ">");
urlString = urlString.replace(/€/g, "&");
urlString = urlString.replace(/¥/g, ":");
urlString = urlString.replace(/¬/g, "=");
urlString = urlString.replace(/ä/g, "/");
urlString = urlString.replace(/¿/g, "?");
urlString = urlString.replace(/ʅ/g, "'");
}
问候,