我正在尝试添加提醒框,以便用户可以选择是或否或确定和取消,但它无法正常工作。这是我第一次尝试这样做。我正在使用visual studio 2010.我不确定我的代码是否正确。如果我弄错了,有人可以指导我。
这是我的代码:
private void AlertWithOption()
{
Response.Write("<script language='javascript'>");
Response.Write("function onsub() ");
Response.Write("{ ");
Response.Write("var where_to= confirm: (\"Are You sure?\")");
Response.Write("if (where_to== true)");
Response.Write("{ ");
Response.Write("return true");
Response.Write(" }");
Response.Write("else ");
Response.Write("{");
Response.Write("return false;");
Response.Write(" } ");
Response.Write("} ");
Response.Write("</script>");
}
答案 0 :(得分:1)
首先我会尝试改变这个:
Response.Write("var where_to= confirm: (\"Are You sure?\")");
到此:
Response.Write("var where_to= confirm(\"Are You sure?\")");
(方法为confirm()
而不是confirm:()
)
答案 1 :(得分:1)
如前所述,您的代码中有一个额外的冒号。但是,由于confirm
javascript方法返回一个布尔值,因此不需要冗长的if / then逻辑。您的代码可以压缩为3行:
Response.Write("<script>");
Response.Write("function onsub() { return confirm(\"are you sure?\"); }");
Response.Write("</script>");
答案 2 :(得分:1)
修改此行代码 - &gt; Response.Write(“var where_to = confirm:(\”你确定吗?\“)”);
试试这个 - &gt; Response.Write(“var where_to = confirm(”你确定吗?“)”);
答案 3 :(得分:1)
方法confirm()是正确的但是里面的字符串应该在双引号内确认(“你确定吗?”);
答案 4 :(得分:1)
使用confirm()
功能。
private void AlertWithOption()
{
Response.Write("<script language='javascript'>");
Response.Write("function onsub() ");
Response.Write("{ ");
Response.Write("return confirm(\"Are you sure?\")");
Response.Write("} ");
Response.Write("</script>");
}
我认为你在confirm()
答案 5 :(得分:0)
我不认为你在确认之后想要冒号,你可以这样做
Response.Write("<script language='javascript'>");
Response.Write("function onsub() ");
Response.Write("{ ");
Response.Write("return confirm(\"Are you sure?\")");
Response.Write("} ");
Response.Write("</script>");