為什么點擊取消還會彈出窗口呢?
<!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 newwindow=confirm("是否打開新窗口?");
if(newwindow){
? ? ?var url=prompt("請輸入您希望打開的網(wǎng)址"," http://idcbgp.cn/"); ?
? ? ?window.open('add','_blank','width=400,height=500,menubar=no,toolbar=no, status=no,scrollbars=no') ?;?
? }
? else;
? ? }
? </script>?
?</head>?
?<body>?
?<input type="button" value="新窗口打開網(wǎng)站" onclick="openWindow()" />?
?</body>
2017-08-03
confirm那里的取消是可以取消的,但是prompt的返回值是默認值或者你的輸入值,并不是null,所以點擊取消就相當于默認,至于confirm的判斷,沒有必要寫成if(newwindow==true),直接寫成if(newwindow)即可,因為為真即可進入if,這是編程的基礎知識了。
2017-08-02
因為你的判斷永遠為真,點啥都會彈
2017-08-02
因為你只判斷了。newwindow,而沒有判斷url
2017-08-01
if(url != null){
?????????????????? window.open(url,'_blank','width=400,height=500,menubar=no,toolbar=no');? ?
??????????? }
2017-08-01
if(newwindow)這里沒有加判斷條件newwindow==ture