請問這段代碼哪里有問題 點擊確定不出現網頁
<!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 nw=confirm("是否打開新的窗口?");
? ? ? ? if (nw=="true")
? ? ? ? var nw=prompt('請輸入網址','http://www.xianlaiwan.cn/');
? ? ? ? nw('http://www.xianlaiwan.cn/','_blank','width=400,height=500,menubar=no,toolbar=no');
? ? ? ? }
? ? ? ? else
? ? ? ? {
? ? ? ? ? ? document.write('沒有任何操作');
? ? ? ? }
? ? // 新窗口打開時彈出確認框,是否打開
? ? // 通過輸入對話框,確定打開的網址,默認為 http://www.xianlaiwan.cn/
? ? //打開的窗口要求,寬400像素,高500像素,無菜單欄、無工具欄。
? ??
? ??
? </script>?
?</head>?
?<body>?
?<input type="button" value="新窗口打開網站" onclick="openWindow()" />?
?</body>
</html>
2016-01-06
問題有點多。看下我改的代碼,對照下:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title> new document </title> ?
??? <script type="text/javascript">
??????? function openwindow(){//函數名要一致,區分大小寫。之前你下面的函數名寫成openWindow(),跟這個不同。
??????????? var nw=confirm("是否打開新的窗口?");
??????????? if (nw==true){ //true或者false是js的一種數據類型,而'true'是字符串,是不同的,所以用true比較。
??????????????? var nw=prompt('請輸入網址','http://www.xianlaiwan.cn/');
??????????????? //nw是得到prompt輸入的網址。然后用window.open打開新窗口,不是nw。
??????????????? window.open(nw,'_blank','width=400,height=500,menubar=no,toolbar=no');
??????????? }//你之前沒有把if內容用{}括起來
??????????? else
??????????? {
??????????????? document.write('沒有任何操作');
??????????? }
??????? }//函數內容也是要在{}內,
??? </script>
</head>
<body>
??? <input type="button" value="新窗口打開網站" onclick="openwindow()" />
</body>
</html>
2016-01-06
有好處錯誤:
1、true是布爾值,去掉true的引號
2、(nw=true)后面缺少一個{
3、函數最后面少一個}
4、函數名稱跟onclick里面寫的不一致,應該是openwindow而不是openWindow,注意區分大小寫
5、nw('http://www.xianlaiwan.cn/','_blank','width=400,height=500,menubar=no,toolbar=no');?需要修改成
window.open(nw,'_blank','width=400,height=500,menubar=no,toolbar=no');
2016-01-06
2016-01-06
?onclick=openWindow()?和 function openwindow() ?加下劃線大小寫你寫得不一樣
2016-01-06
nw('http://www.xianlaiwan.cn/','_blank','width=400,height=500,menubar=no,toolbar=no');這句話寫錯了,應該是window.open(nw,'_blank','width=400,height=500,menubar=no,toolbar=no');
2016-01-06
你都沒有調用window.open方法,怎么彈出新頁面呢