js三种消息框总结-警告框、确认框、提示框

js消息框类别:警告框、确认框、提示框

警告框:alert("文本");

确认框:confirm("文本");

提示框:prompt("文本","默认值");

一:confirm使用范例

<script type="text/javascript">

           function test(){

                 var res = confirm("请选择");

                  if(res == true){

                        document.write("你点击了确定");

                   }else{

                         document.write("你点击了取消");

                    }

            }

</script>

<input type="button" onclick="test()" value="confirm使用范例">

二:prompt使用范例:

<script type="text/javascript">

    function test(){

          var name = prompt("名称","jack");

          if(name!=null && name!=""){

               document.write("hello" + name);

           }

    }

</script>

<input type="button" onclick="test()" value="prompt使用范例">

posted @ 2016-08-20 11:47  模糊的星空  阅读(14961)  评论(1编辑  收藏  举报