通過(guò)練習(xí)javascript中的document.write()輸出展示;消息彈出框alert(字符串或變量);消息對(duì)話(huà)框confirm(str);用戶(hù)交互的信息prompt(str1, str2);打開(kāi)新窗口window.open([URL], [窗口名稱(chēng)], [參數(shù)字符串]);window.close();//關(guān)閉本窗口或者是<窗口對(duì)象>.close();//關(guān)閉指定的窗口的學(xué)習(xí),下面根據(jù)要求測(cè)試:
1、新窗口打開(kāi)時(shí)彈出確認(rèn)框,是否打開(kāi)
提示: 使用 if 判斷確認(rèn)框是否點(diǎn)擊了確定,如點(diǎn)擊彈出輸入對(duì)話(huà)框,否則沒(méi)有任何操作。
2、通過(guò)輸入對(duì)話(huà)框,確定打開(kāi)的網(wǎng)址,默認(rèn)為 https://www.cnblogs.com/dhnblog/
3、打開(kāi)的窗口要求,寬400像素,高500像素,無(wú)菜單欄、無(wú)工具欄。
個(gè)人代碼展示:
1 <!DOCTYPE html> 2 <html> 3 <head> 4 <meta charset="utf-8"> 5 <title>編程練習(xí)挑戰(zhàn)</title> 6 <script type="text/javascript"> 7 function rec(){ 8 // var ceshi=confirm("新窗口打開(kāi)時(shí)彈出確認(rèn)框,是否打開(kāi)") 9 var ceshi=prompt('新窗口打開(kāi)時(shí)彈出確認(rèn)框,是否打開(kāi)','https://www.cnblogs.com/dhnblog/'); 10 if(ceshi!=null){ 11 window.open('https://www.cnblogs.com/dhnblog/','_blank','width=400px,height=500px,menubar=no,toolbar=no') 12 } 13 else{ 14 document.write('haode') 15 } 16 } 17 </script> 18 </head> 19 <body> 20 <input type="button" name="" id="" value="新窗口打開(kāi)網(wǎng)站" onclick="rec()"/> 21 </body> 22 </html>
正確代碼展示:
1 <!DOCTYPE html> 2 <html> 3 <head> 4 <meta charset="utf-8"> 5 <title>瀏覽器對(duì)象</title> 6 <script type="text/javascript"> 7 function ceshi(){ 8 if(confirm('確定打開(kāi)新窗口嗎')) 9 { 10 var url=prompt('請(qǐng)輸入一個(gè)網(wǎng)址','https://www.baidu.com/'); 11 window.onpen(url,'_blank','toolbar=no,menubar=no,scrollbars=yes,width=400,height=400'); 12 } 13 } 14 </script> 15 </head> 16 <body> 17 <input type="button" name="" id="" value="新窗口打開(kāi)網(wǎng)站" onclick="ceshi()" /> 18 </body> 19 </html>
聯(lián)系客服