各位大觸幫看看這代碼哪里出問題了
?function openwidow()
? ? {
? ? ? ? var open=confirm("是否打開新建窗口?");
? ? if(open=true)
? ? {
? ? ? ? var close=prompt("確認打開嗎?","http://www.baidu.com/");
? ? if(close!=null)
? ? { window.open(close,"_blank","width=600,height=800");}
? ? else{alert("再見");}
? ? }
? ? else{alert("goodbye");}
? ? }
2016-09-05
?function openwidow(){
????? ?var open=confirm("是否打開新建窗口?");
? ? //判斷是否打開窗口
? ??
? ? ? ? if(open==true){
????????? var close=prompt("確認打開嗎?","http://www.baidu.com/");
? ? ? ? }else{
????????????alert("goodbye");
?????????}
? ? //文本框輸入確認是否打開該網址
? ? ? ? if(close!=null){?
? ? ? ? ? ? window.open("http://www.baidu.com/","_blank","width=600,height=800");
? ? ? ? }else{
? ? ? ? ? ? alert("再見");??
? ? ? ? }
? ? }
你的問題是
你把if-else嵌套想復雜了
你定義的close變量用prompt返回的值是文本框中輸入的值,所以你下面用window.open()方法時不應該將close傳入,而是直接給網址。
2016-09-06
<!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 close=prompt("確認打開嗎?","http://www.baidu.com/");
??? if(close!==null)
??? { window.open(close,"_blank","width=600,height=800");}
??? else{alert("再見");}
??? }
??? else{alert("goodbye");}
??? }
??? // 新窗口打開時彈出確認框,是否打開
??? // 通過輸入對話框,確定打開的網址,默認為 http://www.xianlaiwan.cn/
??? //打開的窗口要求,寬400像素,高500像素,無菜單欄、無工具欄。
?? ?
?? ?
? </script>
?</head>
?<body>
????? <input type="button" value="新窗口打開網站" onclick="openwindow()" />
?</body>
</html>
2016-09-05
function openwidow()和底下onclick="openWindow()"寫的不一樣;
if(open=true)應該是 ?== ? ?一個=是賦值 ?
if(close!=null)
2016-09-05
function openwidow()和底下onclick="openWindow()"寫的不一樣;
if(open=true)應該是 ?== ? ?一個=是賦值 ?
if(close!=null)
2016-09-05
第10行,if(open == true)
2016-09-05
應該是open==true。但是,你這段代碼能打開百度。我也疑惑了。
2016-09-05
if(open=true)應該是 ?== ? ?一個=是賦值 ??