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