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

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

為什么連確認框都沒有彈出?

<!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 mywin=confirm("是否打開網頁?");

? ? ? ? if(mywin==true)

? ? ? ?{

? ? ? ? var url=prompt("http://www.xianlaiwan.cn/");?

? ? ? ? if(url!=null)

? ? ? ?{ ? ? ? ?

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

? ? ? ?}

? ? ? ? ? ?else

? ? ? ? {

? ? ? ? ? ? alert("再見!");

? ? ? ? ? ??

? ? ? ? }

? ? ? ? ? ?else

? ? ? ?{

? ? ? ? ? ?alert("再見!");

? ? ? ? ? ?

? ? ? ?}


? ? ? ?}

? ? ? ?

? ? ? ??

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


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


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

? ??

? ??

? </script>?

?</head>?

?<body>?

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

?</body>

</html>


正在回答

4 回答

因為你第一個if(mywin==true)判斷的大括號把else括進去了,導致JavaScript語句出錯,然后就全都不會執行了。

function openWindow(){

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

? ? ? ? if(mywin==true)

? ? ? ? {

? ? ? ? ? ? var url=prompt("http://www.xianlaiwan.cn/");?

? ? ? ? ? ? if(url!=null)

? ? ? ? ? ? {? ? ? ? ?

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

? ? ? ? ? ? }

? ? ? ? ? ? else

? ? ? ? ? ? {

? ? ? ? ? ? ? ? alert("再見!");

? ? ? ? ? ? }

? ? ? ? }//你就是這個大括號放錯地方了

? ? ? ? else

? ? ? ? {

? ? ? ? ? ?alert("再見!");

? ? ? ? }??

? ? }

修改結果是這樣

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

已解決多謝

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

<!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 myself=confirm("是否打開網頁?");

? ? ? ? if (myself==true)

? ? ? ? ? ? {

? ? ? ? ? ? ? ? window.open('http://www.xianlaiwan.cn/','_blank','width=400,height=500,menuber=no,toolbar=no')

? ? ? ? ? ? }

? ? ? ? else

? ? ? ? ? ? {

? ? ? ? ? ? ? ? window.close();

? ? ? ? ? ? }

? ? ? ? }

? </script>?

?</head>?

?<body>?

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

?</body>

</html>


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

qq_慕的地1326435

參考一下,我第一次做也是后面發現是if沒有呼出,是白字所以無效,就把if那段刪了重寫,就可以了,另外網址也有問題,空白的,可以用上一章的網址
2019-11-21 回復 有任何疑惑可以回復我~
#2

方木學長

你的代碼也不行,點擊取消按鈕應該不做任何操作,可你寫的代碼,直接把當前網頁關閉
2019-11-23 回復 有任何疑惑可以回復我~

可以看到啊,會不會是瀏覽器的問題?

我的代碼,你試試:

<!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 myconfirm=confirm("是否打開?");

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

if(myconfirm)

{

? ? var myprompt=prompt("請輸入網址:","http://www.xianlaiwan.cn");

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

window.open(myprompt,"_blank","width=400,height=500,menubar=no,toolbar=no");

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

}? ?

? }? ?

? </script>?

?</head>?

?<body>?

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

?</body>

</html>


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

方木學長

你的代碼有bug,在輸入框里點擊取消按鈕,不應該跳出一個頁面
2019-11-23 回復 有任何疑惑可以回復我~
#2

方木學長

if(myconfirm) { var myprompt=prompt("請輸入網址:","http://www.xianlaiwan.cn"); // 通過輸入對話框,確定打開的網址,默認為 http://www.xianlaiwan.cn/ if(my prompt!=null){ window.open(myprompt,"_blank","width=400,height=500,menubar=no,toolbar=no"); //打開的窗口要求,寬400像素,高500像素,無菜單欄、無工具欄。 } }
2019-11-23 回復 有任何疑惑可以回復我~

舉報

0/150
提交
取消

為什么連確認框都沒有彈出?

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

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

幫助反饋 APP下載

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

公眾號

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