到底哪兒錯了...
<html>
?<head>
? <title> new document </title> ?
? <meta http-equiv="Content-Type" content="text/html; charset=gbk"/>? ?
? <script type="text/javascript">
? function openWindow(){
????? var message=confirm("是否要打開一個新網頁?");
????? if(message==true){
????????? var website=prompt("請輸入網站地址:","http://www.xianlaiwan.cn/");
????????? if(website!=null){
????????????? window.open('website','_blank','width=400,height=500,top=0,left=0,menubar=no,toolbar=no,scrollbars=yes,status=yes');
????????? }
????????? else{
????????????? alert("再見吧朋友");
????????? }
????? }
????? else{
????????? alert("再見吧孩子");
????? }
? }
? openWindow();
? </script>
?</head>
?<body>
?? ?? <input type="button" value="新窗口打開網站" onclick="openWindow()" />
?</body>
</html>
運行不了,有大神能幫忙指出錯誤嗎?
2016-03-16
第一:?window.open('website','_blank','width=400,height=500,top=0,left=0,menubar=no,toolbar=no,scrollbars=yes,status=yes');
website的單引號應該去掉。
第二:?openWindow();
? </script>?
這里不需要再調用openWindow()了,函數是通過點擊觸發的。不用再調用
第三:這節練習不驗證代碼,你把代碼保存成.html 直接在瀏覽器就可以運行了。不需要依賴這里的環境
2016-03-16
window.open('website',
這里website是變量,不需要添加''包括。
2016-03-16
window.open('website','_blank','width=400,height=500,top=0,left=0,menubar=no,toolbar=no,scrollbars=yes,status=yes');?
這里website是變量,不需要添加''包括。