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