如何使用JavaScript警告,使用户可以选择 [英] how to use javascript alert so that user can choose

查看:113
本文介绍了如何使用JavaScript警告,使用户可以选择的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想补充一个警告框,以便用户可以选择是或否确定和取消,但它不能正常工作。这是我想做到这一点我的第一次。我使用Visual Studio 2010中,我不知道如果我的code是正确的。任何人都可以请指导我,如果我错了。

这是我的code:

 私人无效AlertWithOption()
  {
     的Response.Write(< SCRIPT LANGUAGE =JavaScript的'>中);
     回复于(功能onsub());
     的Response.Write({);
     的Response.Write(VAR where_to =确认:(\\?你确定\\));
     的Response.Write(如果(where_to ==真));
     的Response.Write({);
     的Response.Write(返回true);
     的Response.Write(});
     的Response.Write(其他);
     的Response.Write({);
     的Response.Write(返回false;);
     的Response.Write(});
     的Response.Write(});
     回复于(&下; /脚本>中);
   }


解决方案

使用确认()功能。

 私人无效AlertWithOption()
  {
    的Response.Write(< SCRIPT LANGUAGE =JavaScript的'>中);
    回复于(功能onsub());
    的Response.Write({);
    的Response.Write(回归确认(\\你确定\\));
    的Response.Write(});
    回复于(&下; /脚本>中);
}

我觉得你是在确认的语法()

操作失误

I am trying to add an alert box so that the user can choose either Yes or No or Ok and Cancel, but it is not working correctly. It is my first time I am trying to do this. I am using visual studio 2010. I am not sure if my code is correct. Can anyone please guide me if I am mistaken.

This is my code:

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>");
   }

解决方案

Use confirm() function.

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>");
}

I think you are doing mistake in the syntax of the confirm()

这篇关于如何使用JavaScript警告,使用户可以选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆