在第二個if條件中的 var new=window.open這里 ,打不開網(wǎng)站,但是不賦值只用window.open(' ','',''); 卻可以打開網(wǎng)站了,這是為什么?
<!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 mysin=confirm("是否打開");
??????? if(mysin==true){
??????????? var open=prompt("請輸入網(wǎng)址:");
??????????? if(open!=null){
??????????????? var new=window.open(' http://idcbgp.cn/','xinkou','width=400,height=500,menubar=no,toolbar=no');
??????????? }
??????????? else{
??????????????? alert("取消!");
??????????? }
??????? }
??????? else{
??????????? alert("退出!");
??????? }
???????
??? }
??? // 新窗口打開時彈出確認(rèn)框,是否打開
??? // 通過輸入對話框,確定打開的網(wǎng)址,默認(rèn)為 http://idcbgp.cn/
??? //打開的窗口要求,寬400像素,高500像素,無菜單欄、無工具欄。
???
???
? </script>
?</head>
?<body>
?? <input type="button" value="新窗口打開網(wǎng)站" onclick="openWindow()" />
?</body>
</html>
2019-07-22
因?yàn)閚ew本身是關(guān)鍵字??Javascript 的保留關(guān)鍵字不可以用作變量、標(biāo)簽或者函數(shù)名,你隨便換個其他變量名就可以正常打開了
break case catch continue default delete do else finally for function if in instanceof?new?return?switch?this throw try var void while with 等
2019-07-11
你這樣的話不就是賦值給變量new了嗎,并沒有輸出啊
2019-07-10
<!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 mysin=confirm("是否打開");
if(mysin){
var open=prompt("請輸入網(wǎng)址:");
if(open!=null){
window.open(open,'_top','width=400,height=500,menubar=no,toolbar=no');
}
else{
alert("取消!");
}
}
else{
alert("退出!");
}
}
// 新窗口打開時彈出確認(rèn)框,是否打開
// 通過輸入對話框,確定打開的網(wǎng)址,默認(rèn)為 http://idcbgp.cn/
//打開的窗口要求,寬400像素,高500像素,無菜單欄、無工具欄。
</script>
</head>
<body>
<input type="button" value="新窗口打開網(wǎng)站" onclick="openWindow()" />
</body>
</html>
2019-07-07
?var isOpen = confirm("新建窗口么");
? ? ? ? if(isOpen){
? ? ? ? ? ? window.open("http://idcbgp.cn","_top","width = 400, height = 500, menubar = no, toolbar = no");
? ? ? ? }