打開窗口和關閉窗口為什么button按鈕沒反應??!
<!DOCTYPE html>
<html>
<head>
? ? <meta charset="UTF-8">
? ? <title>Document</title>
? ? <script type="text/javascript">
? ? ? ? function wopen(){
? ? ? ? ? ? ?var window=prompt("http://www.xianlaiwan.cn");
? ? ? ? ? ? ?if(window!=null){
? ? ? ? ? ? ? ? ? ? ?window.open('http://www.xianlaiwan.cn','_blank',width=400px,height=500px,menubar=no,toolbar=no);
? ? ? ? ? ? ?}else{
? ? ? ? ? ? ? ? alert("結束");
? ? ? ? ? ? ?}
? ? ? ? }
? </script>
?</head>
?<body>
? ? ? <input type="button" value="新窗口打開網站" onclick="wopen()" />
?</body>
</html>
2022-03-25
樓上說的都對的親,謝謝建議,我們會完善一下本小節。
2017-02-24
變量不能與js方法名相同,?prompt("http://www.xianlaiwan.cn");?多余
2017-02-24
兩處錯誤
var window=prompt("http://www.xianlaiwan.cn");?//變量不能與js方法名相同,可以命名為_window ,_w1,_w2,...;
??window.open('http://www.xianlaiwan.cn','_blank',width=400px,height=500px,menubar=no,toolbar=no);?//需要給?width=400px,height=500px,menubar=no,toolbar=no 添加引號 ' ' 或 " " , 統一用單引號或雙引號。