使用window.prompt()实现弹出用户输入的对话框

2019-12-18,,

无意中看到window.prompt()方法,之前真没有使用过,孤陋寡闻。不过现在学习下吧。

在网页中,有时需要弹出一个提示框,而且在提示框中还需要用户输入一些内容,这就可以用prompt对象,具体实现用法如下。

<!DOCTYPE html>
 <html>
 <head>
 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
 <script>
   var _saytext = decodeURI("我真笨");
   
   var _text;
   
   var err_list = new Array("别乱填!!","快填,别试了!!");
   
   _text = prompt("在下面输入框填“" + _saytext +"”");
   
   for ( i = 0; _text != _saytext; ++i) {
     if ( i == err_list.length) {
      i = 0;
     }
     alert(err_list[i]);
     _text = prompt("在下面输入框填“" + _saytext +"”");
   }
   
   alert("嗯,这就对了!");
 </script>
 </head>
 </html>

以上所述就是本文的全部内容了,希望大家能够喜欢。

您可能感兴趣的文章:

  • Prompt、Restore命令使用说明
  • JS中confirm,alert,prompt函数使用区别分析
  • JS中confirm,alert,prompt函数区别分析
  • javascript学习笔记(十六) 系统对话框(alert、confirm、prompt)
  • javascript中常见的3种信息提示框(alert,prompt,confirm)
  • PowerShell中prompt函数的妙用
  • js获取会话框prompt的返回值的方法

《使用window.prompt()实现弹出用户输入的对话框.doc》

下载本文的Word格式文档,以方便收藏与打印。