為什么連確認(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(){
? ? ? ? var mywin=confirm("是否打開網(wǎng)頁?");
? ? ? ? if(mywin==true)
? ? ? ?{
? ? ? ? var url=prompt("http://idcbgp.cn/");?
? ? ? ? if(url!=null)
? ? ? ?{ ? ? ? ?
? ? ? ?window.open(url,"_blank","width=400","height=500","menubar=no","toolbar=no");
? ? ? ?}
? ? ? ? ? ?else
? ? ? ? {
? ? ? ? ? ? alert("再見!");
? ? ? ? ? ??
? ? ? ? }
? ? ? ? ? ?else
? ? ? ?{
? ? ? ? ? ?alert("再見!");
? ? ? ? ? ?
? ? ? ?}
? ? ? ?}
? ? ? ?
? ? ? ??
? ? }//新窗口打開時彈出確認(rèn)框,是否打開
? ? // 通過輸入對話框,確定打開的網(wǎng)址,默認(rèn)為 http://idcbgp.cn/
? ? //打開的窗口要求,寬400像素,高500像素,無菜單欄、無工具欄。
? ??
? ??
? </script>?
?</head>?
?<body>?
?<input type="button" value="新窗口打開網(wǎng)站" onclick="openWindow()" />?
?</body>
</html>
2019-11-23
因為你第一個if(mywin==true)判斷的大括號把else括進(jìn)去了,導(dǎo)致JavaScript語句出錯,然后就全都不會執(zhí)行了。
function openWindow(){
? ? ? ? var mywin=confirm("是否打開網(wǎng)頁?");
? ? ? ? if(mywin==true)
? ? ? ? {
? ? ? ? ? ? var url=prompt("http://idcbgp.cn/");?
? ? ? ? ? ? if(url!=null)
? ? ? ? ? ? {? ? ? ? ?
? ? ? ? ? ? ? ? window.open(url,"_blank","width=400","height=500","menubar=no","toolbar=no");
? ? ? ? ? ? }
? ? ? ? ? ? else
? ? ? ? ? ? {
? ? ? ? ? ? ? ? alert("再見!");
? ? ? ? ? ? }
? ? ? ? }//你就是這個大括號放錯地方了
? ? ? ? else
? ? ? ? {
? ? ? ? ? ?alert("再見!");
? ? ? ? }??
? ? }
修改結(jié)果是這樣
2019-11-24
已解決多謝
2019-11-21
<!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 myself=confirm("是否打開網(wǎng)頁?");
? ? ? ? if (myself==true)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? window.open('http://idcbgp.cn/','_blank','width=400,height=500,menuber=no,toolbar=no')
? ? ? ? ? ? }
? ? ? ? else
? ? ? ? ? ? {
? ? ? ? ? ? ? ? window.close();
? ? ? ? ? ? }
? ? ? ? }
? </script>?
?</head>?
?<body>?
? <input type="button" value="新窗口打開網(wǎng)站" onclick="openWindow()" />?
?</body>
</html>
2019-11-21
可以看到啊,會不會是瀏覽器的問題?
我的代碼,你試試:
<!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 myconfirm=confirm("是否打開?");
? ? // 新窗口打開時彈出確認(rèn)框,是否打開
if(myconfirm)
{
? ? var myprompt=prompt("請輸入網(wǎng)址:","http://idcbgp.cn");
? ? // 通過輸入對話框,確定打開的網(wǎng)址,默認(rèn)為 http://idcbgp.cn/
window.open(myprompt,"_blank","width=400,height=500,menubar=no,toolbar=no");
? ? //打開的窗口要求,寬400像素,高500像素,無菜單欄、無工具欄。
}? ?
? }? ?
? </script>?
?</head>?
?<body>?
? <input type="button" value="新窗口打開網(wǎng)站" onclick="openWindow()" />?
?</body>
</html>