string path = Server.MapPath("./");
//path="c:\\users\\sandy\\documents\\visual studio 2012\\Projects\\WebApplication7\\";
Response.Write("<script>alert('" + path + "');</script>");
不弹提示,浏览器报 ncaught SyntaxError: Unexpected token ILLEGAL的错误。
貌似是\ 的原因,不太明白为什么。
string path = Server.MapPath("./");
path内容是c:\users\sandy\documents\....
发送到客户端就是
<script>alert('c:\users\sandy\documents\....');</script>
这样是转义下一个字符了,当然会错,要将path内容修改成c:\\users\\sandy\\documents\\....,这样客户端才是转义\
string path = Server.MapPath("./").Repalce("\\","\\\\");/////////
Response.Write("<script>alert('" + path + "');</script>");