怎么能讓prompt僅僅輸入該網(wǎng)址時才跳轉(zhuǎn)網(wǎng)頁,輸入別的都無效呢
<!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 a=confirm("是否打開?");
if(a==true)
{var b=prompt("確定打開的網(wǎng)址","http://idcbgp.cn/");if (b!=null){window.open('http://idcbgp.cn/','_blank',width=400,height=500);}else{alert("bye");}}
else
{document.write("再見");}
}
</script>?
?</head>?
?<body>?
? <input type="button" value="新窗口打開網(wǎng)站" onclick="openWindow()" />?
?</body>
</html>
但怎么能讓prompt僅僅輸入該網(wǎng)址時才跳轉(zhuǎn)網(wǎng)頁,輸入別的都無效呢
2019-02-11
加一個判斷條件即可,在你的代碼基礎(chǔ)上增減了一些東西:
<!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 a=confirm("是否打開?");
if(a==true)
{
? ? var b=prompt("確定打開的網(wǎng)址");//可省略慕課網(wǎng)網(wǎng)址
? ? if (b != 'http://idcbgp.cn/')
? ? document.write("希望你輸入慕課網(wǎng)網(wǎng)址而不是其他")
? ? else
? ? {
? ? ? ? window.open(a,'_blank',width=400,height=500);
? ? }
? ??
}
else
{
? ? document.write("再見,你不希望打開新網(wǎng)址");
? ??
}
}
</script>?
?</head>?
?<body>?
? <input type="button" value="新窗口打開網(wǎng)站" onclick="openWindow()" />?
?</body>
</html>
2019-06-30
你最后是不是少打了一個else語句
2019-02-11
如果你寫b=="http://idcbgp.cn/"的話,那就說明你輸入的是慕課網(wǎng)的網(wǎng)址,而你想要的也是成功打開手動輸入的慕課網(wǎng)網(wǎng)址,這就對上了呀。反之,當(dāng)b!=時,你唯有輸入除了慕課網(wǎng)網(wǎng)址外的其他東西,后面的這條語句:window.open('http://idcbgp.cn/','_blank',width=400,height=500);}else{alert("bye");才會被執(zhí)行。