這個(gè)問(wèn)題出在哪里
<!DOCTYPE html>
<html>
?<head>
? <title> new document </title>??
? <meta http-equiv="Content-Type" content="text/html; charset=gbk"/>? ?
? <script type="text/javascript">??
? ? var newwindow=confirm(新窗口打開(kāi)網(wǎng)站);
? ? if(newwindow==yes)
? ? {
? ? // 新窗口打開(kāi)時(shí)彈出確認(rèn)框,是否打開(kāi)
? ? var url=prompt("確定打開(kāi)的網(wǎng)址");
? ? if(url!=null)
? ? // 通過(guò)輸入對(duì)話框,確定打開(kāi)的網(wǎng)址,默認(rèn)為 http://idcbgp.cn/
? ? ? ? {windows.open('http;//idcbgp.cn/','_blank','width=400,height=500,toolbar=no,menubar=no');
? ? ? ? }
? ? else
? ? ? ? {alert("再見(jiàn)")};
? ? }
? ? //打開(kāi)的窗口要求,寬400像素,高500像素,無(wú)菜單欄、無(wú)工具欄。
? ? else
? ? {alert("再見(jiàn)")};
? </script>?
?</head>?
?<body>?
? <input type="button" value="新窗口打開(kāi)網(wǎng)站" onclick="openWindow()" />?
?</body>
</html>
2019-05-18
head部分沒(méi)使用函數(shù)openWindow把代碼囊括,openWindow在body部分底部的onclick=的位置,openWindow可以隨便改,上下同步就行。
2019-05-12
<!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 newwindow=confirm("打開(kāi)網(wǎng)站嗎");
? ? if(newwindow){
? ? // 新窗口打開(kāi)時(shí)彈出確認(rèn)框,是否打開(kāi)
? ? ? var url=prompt("確定打開(kāi)的網(wǎng)址","http://idcbgp.cn/");
? ? // 通過(guò)輸入對(duì)話框,確定打開(kāi)的網(wǎng)址,默認(rèn)為 http://idcbgp.cn/
? ? ? window.open(url,'_blank','width=400,height=500,toolbar=no,menubar=no');
? ? ?}
? ? ?else{
? ? ? ? ?alert("goodbye");}
? ? ?}
? ? }
? ? //打開(kāi)的窗口要求,寬400像素,高500像素,無(wú)菜單欄、無(wú)工具欄。
? </script>?
?</head>?
?<body>?
? <input type="button" value="新窗口打開(kāi)網(wǎng)站" onclick="openWindow()" />?
?</body>
</html>
看起來(lái)沒(méi)什么區(qū)別了,為什么還是運(yùn)行不了
2019-05-12
html里面引用的openWindow函數(shù),所以腳本里要把所有代碼放在該函數(shù)里,不然不會(huì)引用
confir里面的參數(shù)是字符串,所以應(yīng)該加雙引號(hào),否則認(rèn)為是變量
newwindow所得到的返回值是true或者false,不能用yes來(lái)比較
url的默認(rèn)值沒(méi)有設(shè)置,也就是prompt的第二個(gè)參數(shù)沒(méi)有設(shè)置
windows.open里面的地址可以直接使用前面定義的url
附上源碼,如有疑問(wèn)請(qǐng)聯(lián)系:
<!DOCTYPE html>
<html>
?<head>
? <title> new document </title>??
? <meta http-equiv="Content-Type" content="text/html; charset=gbk"/>? ?
? <script type="text/javascript">??
? ? function openWindow(){
? ? // 新窗口打開(kāi)時(shí)彈出確認(rèn)框,是否打開(kāi)
? ? var sure=confirm("確定打開(kāi)?");
? ? // 通過(guò)輸入對(duì)話框,確定打開(kāi)的網(wǎng)址,默認(rèn)為 http://idcbgp.cn/
? ? if(sure){
? ? ? ? var url=prompt("輸入打開(kāi)的網(wǎng)址","http://idcbgp.cn/");
? ? //打開(kāi)的窗口要求,寬400像素,高500像素,無(wú)菜單欄、無(wú)工具欄。
? ? ? ? window.open(url,'_blank','width=400,height=500,menubar=no,toolbar=no')
? ? }
? ? }
? ? </script>?
?</head>?
?<body>?
? <input type="button" value="新窗口打開(kāi)網(wǎng)站" onclick="openWindow()" />?
?</body>
</html>