課程
/前端開發(fā)
/JavaScript
/JavaScript入門篇
哪些返回值會觸發(fā)這個if
2018-01-08
源自:JavaScript入門篇 2-7
正在回答
null表示空值,這里把url!=null改成url!=""就會觸發(fā)else的條件,url!=null會彈出個空頁面,可能空頁面就是null值?
null表示空值, 一般建議變量初始化為null, 與undefined區(qū)分開.? 一般函數(shù)在確定會return時也應(yīng)該會return null以表示沒有值.? 譬如document.getElementById('abcasdfasdf')返回null表示沒有獲得任何node
null代表“空”。。你這行代碼var url=prompt("通過輸入對話框,確定打開的網(wǎng)址","http://idcbgp.cn");表示建立一個輸入網(wǎng)址的提示框。如果這里面不輸入任何東西就觸發(fā)不了if,但首先這個提示框會默認(rèn)一個網(wǎng)址就是“http://idcbgp.cn”你把這個刪了,它會觸發(fā)再見。。這就是null為空。。。
uandsun 提問者
<!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("確認(rèn)新建窗口打開網(wǎng)站嗎?");
if(open==true)
? ? // 新窗口打開時彈出確認(rèn)框,是否打開
{var url=prompt("通過輸入對話框,確定打開的網(wǎng)址","http://idcbgp.cn");
if(url!=null)
? ? // 通過輸入對話框,確定打開的網(wǎng)址,默認(rèn)為 http://idcbgp.cn/
{window.open(url,"_blank",'width=400px,height=500px,menubar=no,toolbar=no');? ??
}
? ? //打開的窗口要求,寬400像素,高500像素,無菜單欄、無工具欄。
else
{alert("再見!");}
}? ?
? ? }
? ??
? </script>?
?</head>?
?<body>?
? <input type="button" value="新窗口打開網(wǎng)站" onclick="openWindow()" />?
?</body>
</html>
? function openWindow(){
? ? var mychar = confirm("是否打開新窗口");
? ? if (mychar==true)
? ? {
????// 通過輸入對話框,確定打開的網(wǎng)址,默認(rèn)為 http://idcbgp.cn/
? ? var myaddress;
? ? myaddress=prompt("請輸入網(wǎng)址:");
? ? window.open(myaddress,'_blank','width=400,height=500,meaubar=no,toolbar=no');
找不到這個12行為null的代碼,可以復(fù)制粘貼一份嗎
舉報
JavaScript做為一名Web工程師的必備技術(shù),本教程讓您快速入門
1 回答為什么把贊數(shù)最高的同學(xué)代碼里的set變量去掉之后就無法運(yùn)行了呢?
1 回答同學(xué)代碼怎么弄的
1 回答怎么把寫的代碼放到同學(xué)代碼里
3 回答代碼一樣,為什么另一個同學(xué)的代碼能運(yùn)行,我的卻不可以呢?
3 回答同學(xué)代碼里面function的位置
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號-11 京公網(wǎng)安備11010802030151號
購課補(bǔ)貼聯(lián)系客服咨詢優(yōu)惠詳情
慕課網(wǎng)APP您的移動學(xué)習(xí)伙伴
掃描二維碼關(guān)注慕課網(wǎng)微信公眾號
2018-01-12
null表示空值,這里把url!=null改成url!=""就會觸發(fā)else的條件,url!=null會彈出個空頁面,可能空頁面就是null值?
2018-01-10
null表示空值, 一般建議變量初始化為null, 與undefined區(qū)分開.? 一般函數(shù)在確定會return時也應(yīng)該會return null以表示沒有值.? 譬如document.getElementById('abcasdfasdf')返回null表示沒有獲得任何node
2018-01-09
null代表“空”。。你這行代碼var url=prompt("通過輸入對話框,確定打開的網(wǎng)址","http://idcbgp.cn");表示建立一個輸入網(wǎng)址的提示框。如果這里面不輸入任何東西就觸發(fā)不了if,但首先這個提示框會默認(rèn)一個網(wǎng)址就是“http://idcbgp.cn”你把這個刪了,它會觸發(fā)再見。。這就是null為空。。。
2018-01-08
<!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("確認(rèn)新建窗口打開網(wǎng)站嗎?");
if(open==true)
? ? // 新窗口打開時彈出確認(rèn)框,是否打開
{var url=prompt("通過輸入對話框,確定打開的網(wǎng)址","http://idcbgp.cn");
if(url!=null)
? ? // 通過輸入對話框,確定打開的網(wǎng)址,默認(rèn)為 http://idcbgp.cn/
{window.open(url,"_blank",'width=400px,height=500px,menubar=no,toolbar=no');? ??
}
? ? //打開的窗口要求,寬400像素,高500像素,無菜單欄、無工具欄。
else
{alert("再見!");}
}? ?
else
{alert("再見!");}
? ? }
? ??
? ??
? </script>?
?</head>?
?<body>?
? <input type="button" value="新窗口打開網(wǎng)站" onclick="openWindow()" />?
?</body>
</html>
2018-01-08
? function openWindow(){
? ? // 新窗口打開時彈出確認(rèn)框,是否打開
? ? var mychar = confirm("是否打開新窗口");
? ? if (mychar==true)
? ? {
????// 通過輸入對話框,確定打開的網(wǎng)址,默認(rèn)為 http://idcbgp.cn/
? ? var myaddress;
? ? myaddress=prompt("請輸入網(wǎng)址:");
? ? //打開的窗口要求,寬400像素,高500像素,無菜單欄、無工具欄。
? ? window.open(myaddress,'_blank','width=400,height=500,meaubar=no,toolbar=no');
? ? }
? ? }
2018-01-08
找不到這個12行為null的代碼,可以復(fù)制粘貼一份嗎