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