亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

請問為什么在輸入網址運行的時候,如何實現按“取消”鍵彈出“結束”?求解!!為什么我的代碼點擊取消鍵還是彈出新的網頁?

<!DOCTYPE html>

<html>

?<head>

? <title> new document </title> ?

? <meta http-equiv="Content-Type" content="text/html; charset=gbk"/> ??

? <script type="text/javascript"> ?

? ? function openWindow(){

? ? ? ? var open = confirm("是否打開新網頁?");

? ? ? ?

? ? // 新窗口打開時彈出確認框,是否打開

? ? ? ? if(open==true){

? ? ? ? ? ?var newwindow=prompt("請確定打開或重新輸入網址","http://www.xianlaiwan.cn");

? ? // 通過輸入對話框,確定打開的網址,默認為 http://www.xianlaiwan.cn/

? ? ? ? ? ? if(newwindow==null){

? ? ? ? ? ? ? ? window.open(newwindow,"_blank",'width=400px,height=500px,menubar=no,toolbar=no');?

? ? ? ? ? ? }

? ? ? ? ? ? else{

? ? ? ? ? ? ? ? window.open(newwindow);

? ? ? ? ? ? }

? ? ? ? }

? ? //打開的窗口要求,寬400像素,高500像素,無菜單欄、無工具欄。

? ? ? ? else{

? ? ? ? ? ? alert("結束");

? ? ? ? }

? ? }

? </script>?

?</head>?

?<body>?

?<input type="button" value="新窗口打開網站" onclick="openWindow()" />?

?</body>

</html>


正在回答

2 回答

....因為你給他設置了默認值,就算你不輸入也是http://www.xianlaiwan.cn,你只需要把默認值改為",然后把判斷條件改為"if(newwindow=="")即可

0 回復 有任何疑惑可以回復我~
#1

我的故事你不懂 提問者

非常感謝!
2016-11-08 回復 有任何疑惑可以回復我~

因為你的代碼中

? if(newwindow==null){

? ? ? ? ? ? ? ? window.open(newwindow,"_blank",'width=400px,height=500px,menubar=no,toolbar=no');?

? ? ? ? ? ? }

? ? ? ? ? ? else{

? ? ? ? ? ? ? ? window.open(newwindow);

? ? ? ? ? ? }

表示提示對話框彈出后,

點擊“取消”返回“null”值執行if條件語句中判斷為真的命令,即下列命令打開窗口window.open(newwindow,"_blank",'width=400px,height=500px,menubar=no,toolbar=no');?

點擊“確定”即返回“http://www.xianlaiwan.cn”并存儲在申明的變量newwindow中執行if條件語句中else后的命令也是打開窗口

?window.open(newwindow);


0 回復 有任何疑惑可以回復我~

舉報

0/150
提交
取消

請問為什么在輸入網址運行的時候,如何實現按“取消”鍵彈出“結束”?求解??!為什么我的代碼點擊取消鍵還是彈出新的網頁?

我要回答 關注問題
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號