沒(méi)有默認(rè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 myMessage=confirm("確定要打開(kāi)嗎?");
??? // 通過(guò)輸入對(duì)話(huà)框,確定打開(kāi)的網(wǎng)址,默認(rèn)為 http://idcbgp.cn/
??????? if(myMessage=="true"){
??????????? var targetWeb=prompt("請(qǐng)輸入要打開(kāi)的網(wǎng)址", "http://idcbgp.cn");
??? //打開(kāi)的窗口要求,寬400像素,高500像素,無(wú)菜單欄、無(wú)工具欄。
??????????? if(targetWeb!=null)
??????????????? window.open(targetWeb,'_blank','width=400,height=500,menubar=no,toolbar=no');
??????? }
??????? else {
??????????? targetWeb=prompt("重新輸入網(wǎng)址");
??????? }
??? }
??? openWindow();
? </script>
?</head>
?<body>
?? <input type="button" value="新窗口打開(kāi)網(wǎng)站" onclick="openWindow()" />
?</body>
</html>
2019-01-20
?if(myMessage=="true"){? 這行 true不應(yīng)該加雙引號(hào)
去掉就可以了
還有你的targetWeb是定義在if中的,我想問(wèn)會(huì)不會(huì)在else中算作沒(méi)有定義
2019-01-20
你的else是對(duì)if(targetWeb!=null)的吧? 那個(gè)花括號(hào)是不是加錯(cuò)地方了