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使用范例">


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM