為什么打不開新窗口
<!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 x = confirm("是否打開一個(gè)網(wǎng)頁");
? ? // 新窗口打開時(shí)彈出確認(rèn)框,是否打開
? ? ? ? ? ?if(a==true){
? ? ? ? ? ? ? var b =prompt("請(qǐng)輸入你要打開的網(wǎng)址","http://idcbgp.cn/");
? ? ? ? ? ?}
? ? ? ? ? ? ? if(b!=null){
? ? ? ? ? ? ? ? ?window.open("http://idcbgp.cn/","_blank","width=400,height=500,menubar=no,toolbar=no");
? ? ? ? ?else{
? ? ? ? ? ? ?alert("拜拜");
? ? ? ? ?}
? ? ?}
? ? ? else{
? ? ? alert("拜拜");
? ?}
??
? }
? ? // 通過輸入對(duì)話框,確定打開的網(wǎng)址,默認(rèn)為 http://idcbgp.cn/
? ? //打開的窗口要求,寬400像素,高500像素,無菜單欄、無工具欄。
? ??
? ??
? </script>?
?</head>?
?<body>?
? <input type="button" value="新窗口打開網(wǎng)站" onclick="openWindow()"/>?
?</body>
</html>
2021-06-29
?var x = confirm("是否打開一個(gè)網(wǎng)頁")這句comfirm()賦值給了變量x;
?if(a==true){var b =prompt("請(qǐng)輸入你要打開的網(wǎng)址","http://idcbgp.cn/");}你這里的判斷的時(shí)候應(yīng)該用變量x,而不是用a,因?yàn)閏onfirm返回的是true和false,所以x被賦值之后是true或者false,你這里是要判斷x是不是true,如果等于就執(zhí)行代碼塊。
?if(b!=null){window.open("http://idcbgp.cn/","_blank","width=400,height=500,menubar=no,toolbar=no") else{ alert("拜拜");} 這里用b!=null來判斷是否為空值,可能會(huì)出現(xiàn)判斷無效的情況,因?yàn)橛锌赡苣J(rèn)是空字符所以可以用b!=""來判斷
2021-06-20
你好,我剛剛試了一下
首先,?var x = confirm("是否打開一個(gè)網(wǎng)頁"); 這里只是賦值,這樣不算是使用,應(yīng)該把 confirm前面的刪掉,然后
if(a==true){
? ? ? ? ? ? ? var b =prompt("請(qǐng)輸入你要打開的網(wǎng)址","http://idcbgp.cn/");
? ? ? ? ? ?}
這里a沒有賦值,a的初始值默認(rèn)是隨機(jī)還是0來著,我不知道,但絕不會(huì)等于true,另外因?yàn)閍沒有賦值,發(fā)生報(bào)錯(cuò),就沒執(zhí)行后面的語句了,還有后面的,這里也錯(cuò)了,b的賦值在上一個(gè)if 里有效,這個(gè)if 里b就失效了,也報(bào)錯(cuò)
?if(b!=null){
? ? ? ? ? ? ? ? ?window.open("http://idcbgp.cn/","_blank","width=400,height=500,menubar=no,toolbar=no");
? ? ? ? ?else{
? ? ? ? ? ? ?alert("拜拜");
? ? ? ? ?}
? ? ?}