亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

以下這段代碼為什么不能執行啊。。。求大神解析

以下這段代碼為什么不能執行啊。。。求大神解析

慕粉3414280 2016-06-08 13:56:45
<!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("拜拜`");}? ? ? ??? ? ? ? else{alert("拜拜`");}? ? }? ??? ??? </script>??</head>??<body>? ?<input type="button" value="新窗口打開網站" onclick="openWindow()" />??</body></html>
查看完整描述

4 回答

已采納
?
Suber丶林

TA貢獻75條經驗 獲得超180個贊

① 既然你用H5的文檔標準,那你的編碼就得改成H5的寫法,即把meta修改成<meta charset="utf-8">

② H5中引入JavaScript和CSS都不用指定type屬性,所以可以把<script>標簽中的type="text/javascript"去掉

③ 你的if else嵌套錯了

④ 你的變量a只用了1次,可以省略掉

⑤ 布爾值之間就不需要判斷是否與布爾值相等,直接判斷即可,再者undefinal、null、0、NaN、''、都是false

⑥ 你的prompt()第二個參數冒號和window.open()第一個參數中冒號使用了全角狀態

修改后代碼為:

<!DOCTYPE?html>
<html>
<head>
??<title>?new?document?</title>
??<meta?charset="utf-8">
??<script>
??function?openWindow()?{
????//?變量a只用了1次,所以沒必要存儲變量
????if?(confirm("是否打開該網址?"))?{
????
??????//?全角冒號換成半角冒號
??????var?b?=?prompt("通過輸入對話框,確定打開這個網址?",?"http://www.xianlaiwan.cn/");?
??????
??????//?這里null為false
??????if?(b)?{
?????????//?全角冒號換成半角冒號
?????????window.open("http://www.xianlaiwan.cn/",?"_blank",?"width=400?height=500?");
?????????//?有個疑問,業務是否為打開用戶輸入的URL?是的話,如下:
?????????//?window.open(b,?"_blank",?"width=400?height=500?");
??????}?else?{
??????????alert("拜拜`");
??????}
??????????
????//?第二個alert要放外面
????}?else?{
??????alert("拜拜`");
????}
??}
??</script>
</head>
<body>
????<input?type="button"?value="新窗口打開網站"?onclick="openWindow()"?/>
</body>
</html>


查看完整回答
3 反對 回復 2016-06-08
?
剛毅87

TA貢獻345條經驗 獲得超309個贊

<!DOCTYPE?html>
<html>

	<head>
		<meta?charset="UTF-8">
		<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?應該寫在上個?if?里面
					if?(b?!=?null)?{
						window.open("http://www.xianlaiwan.cn/",?"_blank",?"width=400?height=500?");
					}?else?{
						alert("拜拜`");
					}?
				}else?{
					alert("拜拜`");
				}
			}
		</script>
	</head>

	<body>
		<input?type="button"?value="新窗口打開網站"?onclick="openWindow()"?/>
	</body>

</html>

看看是否符合你的要求,可以再提

望采納

查看完整回答
2 反對 回復 2016-06-08
?
qyy2499760117_葉子

TA貢獻188條經驗 獲得超91個贊

你的判斷語氣不合規范,錯了,應該是If()else(),要么就if(),再if(),不能亂的。

<!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/");
? ? ? ? ? ?}

? ? ? ? ? ?else {
? ? ? ? ? ? ? ?alert("拜拜`");
? ? ? ? ? ?}
? ? ? ?}

? ? ? ?if (b != null) {
? ? ? ? ? ?window.open("http://www.xianlaiwan.cn/", "_blank", "width=400 height=500 ");
? ? ? ?} else {
? ? ? ? ? ?alert("拜拜`");
? ? ? ?}


? ?</script>
</head>
<body>
<input type="button" value="新窗口打開網站" onclick="openWindow();"/>
</body>
</html>

查看完整回答
1 反對 回復 2016-06-08
  • 4 回答
  • 2 關注
  • 2226 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號