4 回答

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>

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>
看看是否符合你的要求,可以再提
望采納

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>
添加回答
舉報