為什么要用if(url!=null)
<!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 open=confirm("是否打開新窗口");
? ? ? ? if(open==true){
? ? ? ? ? ? var url=prompt("打開默認網址","http://www.xianlaiwan.cn");
? ? ? ? ? ? if(url!=null){
? ? ? ? ? ? ? ? window.open(url,"_blank","width=400,height=500,menuba=no,toolba=no");
? ? ? ? ? ? }
? ? ? ? ? ? else{
? ? ? ? ? ? ? ? alert("再見?。?!")
? ? ? ? ? ? }
? ? ? ? }
? ? ? ? else{
? ? ? ? ? ? alert("再見!")
? ? ? ? }
? ? }
? ??
? </script>?
?</head>?
?<body>?
?<input type="button" value="新窗口打開網站" onclick="openWindow()" />?
?</body>
</html>
為什么用if(url!=null)就可以,用if(url=true)就不行呢?
2017-04-24
因為url是你輸入的網址 有值或者沒值(null) 不能用true或者false判斷 而且url =true 和 url ==true 完全不同 前者是賦值 后者是判斷布爾類型
我也有點疑問就是 當你輸入字符時(例如true),會跳到http://www.xianlaiwan.cn/code/true?這個地址上去
2017-04-22
因為prompt有確認和取消兩個選項,當你選擇取消的時候,是沒有數據傳輸的,url也沒有被賦值,要先判斷有沒有被賦值才能打開網頁
2017-04-21
得確定是否有網址傳進來,才能確定打開這個網址,如果沒有網址傳進來,就直接退出