prompt可以設置默認參數,沒有輸入點擊確定時可以給變量賦值為默認值
?<script type="text/javascript">??
? ? function openWindow(){
? ? ? ? var mymassage = confirm("是否打開一個新網站?");//confirm(文本)
? ? ? ? if(mymassage == true){
? ? ? ? ? ? webchar = prompt("請輸入網址:(提示:以www開頭?。?!)","");//prompt(文本,設置默認文本)
? ? ? ? ? ? //打開輸入的網址
? ? ? ? ? ? if(webchar != null && webchar !=''){
? ? ? ? ? ? webchar = 'http://'+ webchar;
? ? ? ? ? ? window.open(webchar,'idth = 400,height = 500,menubar = no,toolbar = no');
? ? ? ? ? ? }
? ? ? ? ? ? //沒有輸入點確認時打開默認窗口
? ? ? ? ? ? else if(webchar == '')window.open('http://www.xianlaiwan.cn','idth = 400,height = 500,menubar = no,toolbar = no');
? ? ? ? ? ? //點擊取消不執行
? ? ? ? ? ? else return null;
? ? ? ? }
? ? ? ? else return null ;
? ? }?
? </script>?
2020-06-24
解決了頭疼半天為啥不輸入值點確定相關操作的問題?