js confirm()方法的使用方法实例

  如果用户点击确定按钮,则 confirm() 返回 true。如果点击取消按钮,则 confirm() 返回 false。

  在用户点击确定按钮或取消按钮把对话框关闭之前,它将阻止用户对浏览器的所有输入。在调用 confirm() 时,将暂停对 JavaScript 代码的执行,在用户作出响应之前,不会执行下一条语句。

  下面我们通过这两个小例子,来了解一下它的使用方法吧:

  

复制代码 代码如下:

  <html>

  <head>

  <title>confrim 的使用方法</title>

  <script type="text/javascript">

  function clear1()

  {

  if(confirm("确定要清空数据吗?"))

  {

  document.main.text1.value="";

  }

  }

  </script>

  </head>

  <boty>

  <form name="main">

  <input type="text" name="text1"/>

  <input type="button" name="submit" value="数据清空" onclick="return clear1()"/>

  </form>

  </body>

  </html>

  <html>

  <head>

  <title>js confirm</title>

  <script>

  function begin()

  {

  var a=confirm("郭杨和小代是好朋友吗?");

  if(a==true)

  {

  /*document.write("恭喜你答对了!");*/

  alert("恭喜你答对了!");

  begin();

  }

  else

  {

  /*document.write("你真是猪,这么简单的问题都答不对!");*/

  alert("你真是猪,这么简单的问题都答不对!");

  begin();

  }

  }

  </script>

  </head >

  <body onload="begin()">

  </body>

  </html>