[英]Alert not popping up for string ASP.Net
I'm stuck again with alertboxes!我又被警报框困住了!
This works like a charm:这就像一个魅力:
Response.Write("<script>alert('" + "Hello"+ "');</script>");
result is a string.结果是一个字符串。 I need to display that.
我需要显示它。 This is where my problem comes in. This doesn't popup:
这就是我的问题所在。这不会弹出:
Response.Write("<script>alert('" + result + "');</script>");
I am passing result across many layers.我正在通过许多层传递结果。 Also I have used this format in all pages.
我也在所有页面中使用了这种格式。 Don't want a message box.
不想要一个消息框。 Or a modal popupwindow.
或模态弹出窗口。 I want this.
我要这个。 I checked online and according to the syntax, it is supposed to work!
我在网上查了一下,根据语法,它应该可以工作! Please help!
请帮忙!
To put any value in a Javascript string literal, you need to escape apostrophes (as they are used as the delimiter for the string) and backslashes:要将任何值放入 Javascript 字符串文字中,您需要转义撇号(因为它们用作字符串的分隔符)和反斜杠:
Response.Write(
"<script>" +
"alert('" + result.Replace("'", "\\'").Replace("\\", "\\\\") + "');" +
"</script>"
);
试试这个Response.Write("<script type='text/javascript'>alert('"+result+"')</script>")
Response.Write("<script> alert('" + HttpUtility.HtmlEncode(result) + "'); </script>")
Try this尝试这个
String message = String.format({0}{1}{2},
"<script type='text/javascript'>alert('",
result,
"')</script>");
Response.Write(message);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.