代碼問題,求大神解答
<!DOCTYPE?html> <html?lang="zh-cn"> <head> ????<meta?charset="UTF-8"> ????<title>Title</title> ????<script?type="text/javascript"> ???????function?wopen()?{ ???????????var?open=confirm("是否打開?"); ???????????if(open=true) ???????????{var?url=prompt("通過對話框輸入","http://www.xianlaiwan.cn"); ???????????if(url!=null) ???????????{window.open(url,"_blank",'width=400,height=500,menubar=no,toolbar=no');} ???????????else ?{alert("再見!");} ???????????} ???????????else ?{alert("再見!");} ???????} ? ????</script> </head> <body> <input?type="button"?value="新窗口打開"?onclick="wopen()"/> </body> </html>
請問大家這段代碼哪里出錯,第一次打開點取消會先彈到prompt,然后再點擊一次取消,再彈出(再見)!我看見你們貼的代碼點擊取消都是直接彈出(再見?。?實在找不錯哪里錯了...
2016-10-21
這樣子就可以了!你試試,點擊取消就是“再見!”
2016-10-21
你看下我寫的代碼,執行一下,看看是否跟你想要實現的效果一樣!
我覺得我這個代碼應該是符合題目要求的。如果有不對的地方也請指出。
不甚感激!
2016-10-21
<!DOCTYPE html>
<html>
<head>
? ? <meta charset="UTF-8">
? ? <title>Title</title>
? ? <script type="text/javascript">
? ? ? ?function wopen()
? ? ? ?{
? ? ? ? ? ?var open=confirm("是否打開?");
? ? ? ? ? ?if(open==true)//你這里用的是一個等號,是重新令open等于true,下面的else肯定執行不到了
? ? ? ? ? ?{
? ? ? ? ? ? ? ?var url=prompt("通過對話框輸入","http://www.xianlaiwan.cn");
? ? ? ? ? ? ? ? if(url!=null){
? ? ? ? ? ? ? ? ? ? window.open(url,"_blank",'width=400,height=500,menubar=no,toolbar=no');}
? ? ? ? ? ? ? ? else{alert("再見!");}
? ? ? ? ? ?}
? ? ? ? ? ?else{alert("再見!");}
? ? ? ?}
? ? </script>
</head>
<body>
<input type="button" value="新窗口打開" onclick="wopen()"/>
</body>
</html>
2016-10-20