為什么網(wǎng)址輸入為空的時(shí)候還是能打開一個(gè)空白頁面,而不是輸出網(wǎng)址為空
<!DOCTYPE html>
<html>
?<head>
? <title> new document </title>??
? <meta http-equiv="Content-Type" content="text/html; charset=gbk"/>? ?
? <script type="text/javascript">??
? // 新窗口打開時(shí)彈出確認(rèn)框,是否打開
? ? function openWindow(){
? ? ? ? var open=confirm("是否打開");
? ? ? ? if(open==true)
? ? ? ? {
? ? ? ? //通過輸入對話框,確定打開的網(wǎng)址,默認(rèn)為 http://idcbgp.cn/
? ? ? ? ? ? var url=prompt("請確定打開的網(wǎng)址:",'https://www.zhihu.com/question/30180100');
? ? ? ? //打開的窗口要求,寬400像素,高500像素,無菜單欄、無工具欄。
? ? ? ? ? ? if(url!=null)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? ?window.open(url,'_blank','width=400px,height=500px,nenubar=no,toolbar=no');
? ? ? ? ? ? }
? ? ? ? ? ? else
? ? ? ? ? ? {
? ? ? ? ? ? ? ? document.write("輸入為空");
? ? ? ? ? ? }
? ? ? ? }
? ? ? ??
? ? ? ? else
? ? ? ? {
? ? ? ? ? ? document.write("沒有打開");
? ? ? ? ? ? ? ??
? ? ? ? }
? ? ? ? ? ??
? ? }
? ??
? </script>?
?</head>?
?<body>?
? <input type="button" value="新窗口打開網(wǎng)站" onclick="openWindow()" />?
?</body>
</html>
2021-08-09
?你寫的判斷是有問題的url的值有輸入就是string沒有輸入就是object了只有按取消url才是null 你應(yīng)該看看js手冊