課程
/前端開發
/JavaScript
/JavaScript入門篇
第12行的mes==""為什么替換成mes==null運行結果就不對了
2020-04-08
源自:JavaScript入門篇 2-7
正在回答
因為你在輸入框什么都不輸入的時候發送的字符串是“”而不是null,null代表不存在,但實際上你在輸入框里是有東西的,“”!= 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 mes=prompt("請輸入要訪問的網址:");
? ? ? ? ? ? if(mes=="")
? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? window.open('http://www.xianlaiwan.cn/','_blank','width=400,height=500,menubar=no,toolbar=no');
? ? ? ? ? ? }
? ? ? ? ? ?else
? ? ? ? ? ?{
? ? ? ? ? ? ? ?window.open('https://www.baidu.com/','_blank','width=400,height=500,menubar=no,toolbar=no');
? ? ? ? ? ?}
? ? ? ? }
? ? }
? </script>?
?</head>?
?<body>?
? <input type="button" value="新窗口打開網站" onclick="openWindow()" />?
?</body>
</html>
舉報
JavaScript做為一名Web工程師的必備技術,本教程讓您快速入門
5 回答代碼寫成這樣,為什么運行結果不對
2 回答運行結果不對
5 回答為什么第六行加了script就不顯示結果了呢
3 回答為什么運行不出結果
4 回答為什么第一個能運行第二個運行不了
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號-11 京公網安備11010802030151號
購課補貼聯系客服咨詢優惠詳情
慕課網APP您的移動學習伙伴
掃描二維碼關注慕課網微信公眾號
2020-04-10
因為你在輸入框什么都不輸入的時候發送的字符串是“”而不是null,null代表不存在,但實際上你在輸入框里是有東西的,“”!= null
2020-04-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("是否打開網頁?");
? ? ? ? if(open==true){
? ? ? ? ? ? var mes=prompt("請輸入要訪問的網址:");
? ? ? ? ? ? if(mes=="")
? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? window.open('http://www.xianlaiwan.cn/','_blank','width=400,height=500,menubar=no,toolbar=no');
? ? ? ? ? ? }
? ? ? ? ? ?else
? ? ? ? ? ?{
? ? ? ? ? ? ? ?window.open('https://www.baidu.com/','_blank','width=400,height=500,menubar=no,toolbar=no');
? ? ? ? ? ?}
? ? ? ? }
? ? }
? </script>?
?</head>?
?<body>?
? <input type="button" value="新窗口打開網站" onclick="openWindow()" />?
?</body>
</html>