設(shè)計(jì)有問(wèn)題嗎?麻煩大家給我指點(diǎn)
<!DOCTYPE html>
<html>
?<head>
? <title> new document </title> ?
? <meta http-equiv="Content-Type" content="text/html; charset=gbk"/> ??
? <script type="text/javascript"> ?
? ??
? ? // 新窗口打開(kāi)時(shí)彈出確認(rèn)框,是否打開(kāi)
? ? // 通過(guò)輸入對(duì)話框,確定打開(kāi)的網(wǎng)址,默認(rèn)為 http://idcbgp.cn/
? ? //打開(kāi)的窗口要求,寬400像素,高500像素,無(wú)菜單欄、無(wú)工具欄。
? ? function openwindow(){
? ? ? ? var openpt=confirm("是否打開(kāi)新網(wǎng)頁(yè)");
? ? ? ? if(openpt==true)
? ? ? ? {var address=prompt("http://idcbgp.cn/");
? ? ? ? if(adress!=null){
? ? ? ? ? ? window.open(adress,"_blank",'width=400px,height=500,menubar=no,toolbar=no');
? ? ? ? }
? ? ? ? else
? ? ? ? {
? ? ? ? ? ? alert("結(jié)束");
? ? ? ? }
? ? ? ??
? ? ? ? }else
? ? ? ? alert{"結(jié)束"};
}
? </script>?
?</head>?
?<body>?
?<input type="button" value="新窗口打開(kāi)網(wǎng)站" onclick="openWindow()" />?
?</body>
</html>
2016-04-08
那段代碼是在你的代碼的基礎(chǔ)上修改的,經(jīng)測(cè)試也能運(yùn)行,如果你也看不懂的話,那再看看我簡(jiǎn)化過(guò)的代碼,還是在你的基礎(chǔ)上修改的:
<!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 openpt=confirm("是否打開(kāi)新網(wǎng)頁(yè)");
? ? ? ? if(openpt==true){
? ? ? ? ? ? var address=prompt("請(qǐng)輸入網(wǎng)址", "http://idcbgp.cn");
? ? }if(address!=null){
? ? ? ? ? ? window.open(address,"_blank",'width=400px,height=500,menubar=no,toolbar=no');
? ? ? ? }else{
? ? ? ? ? ? alert("結(jié)束");
? ? ? ? }
? ? }
?</script>?
?</head>?
?<body>?
?<input type="button" value="新窗口打開(kāi)網(wǎng)站" onclick="openWindow()" />?
?</body>
</html>
這樣寫(xiě)的話,不管你是點(diǎn)擊?confirm() 框的取消按鈕,還是點(diǎn)擊?prompt() 框的取消按鈕,都會(huì)彈出?alert("結(jié)束") 提示框。還有你說(shuō)的if同級(jí)別的問(wèn)題,在?openWindow()?這個(gè)函數(shù)里,openpt 和?address 是兩個(gè)不同的變量,在if() 條件表達(dá)式里,它們自然也不同的,所以這兩個(gè) if() 語(yǔ)句并不是同級(jí)別。還有,if(address!=null){} 語(yǔ)句最好不要放在?if(openpt==true){} 語(yǔ)句里,不然當(dāng)你點(diǎn)擊?prompt() 框的取消按鈕后,不會(huì)彈出?alert("結(jié)束") 提示框。這不符合你的設(shè)計(jì)。如果非要放便于你自己理解的話,代碼也可以像你原來(lái)的那么寫(xiě),不過(guò)你寫(xiě)的代碼真的是漏洞百出,寫(xiě)碼的時(shí)候要走點(diǎn)心?。?/p>
<!DOCTYPE html>
<html>
?<head>
? <title> new document </title> ?
? <meta http-equiv="Content-Type" content="text/html; charset=gbk"/> ??
? <script type="text/javascript"> ?
? ??
? ? // 新窗口打開(kāi)時(shí)彈出確認(rèn)框,是否打開(kāi)
? ? // 通過(guò)輸入對(duì)話框,確定打開(kāi)的網(wǎng)址,默認(rèn)為 http://idcbgp.cn/
? ? //打開(kāi)的窗口要求,寬400像素,高500像素,無(wú)菜單欄、無(wú)工具欄。
? ? function openWindow(){
? ? ? ? var openpt=confirm("是否打開(kāi)新網(wǎng)頁(yè)");
? ? ? ? if(openpt==true){
? var address=prompt("http://idcbgp.cn/");
? ? ? ? ? ? ? if(address!=null){
? ? ? ? ? ? ? ? ?window.open(address,"_blank",'width=400px,height=500,menubar=no,toolbar=no');
? ? ? ? }else{
? ? ? ? ? ? alert("結(jié)束");
? ? ? ? }
? ? ? ? }else{
? ? ? ? ? ? alert("結(jié)束");
}
}
? </script>?
?</head>?
?<body>?
?<input type="button" value="新窗口打開(kāi)網(wǎng)站" onclick="openWindow()" />?
?</body>
</html>
2016-04-02
你這樣的設(shè)計(jì)師沒(méi)問(wèn)題,可是寫(xiě)法就有些錯(cuò)了,你這樣寫(xiě)按鈕都打不開(kāi),這是我在你代碼的基礎(chǔ)上改過(guò)的寫(xiě)法,你對(duì)比看看:
? <script type="text/javascript"> ?
? ? function openWindow(){
? ? ? ? var openpt=confirm("是否打開(kāi)新網(wǎng)頁(yè)");
? ? ? ? if(openpt==true){
? ? ? ? ? ? var address=prompt("請(qǐng)輸入網(wǎng)址", "http://idcbgp.cn");
? ? ? ? }
? ? ? ? if(address!=null){
? ? ? ? ? ? window.open(address,"_blank",'width=400px,height=500,menubar=no,toolbar=no');
? ? ? ? }else if(openpt==false){
? ? ? ? ? ? alert("結(jié)束");
? ? ? ? }else if(address==null){
? ? ? ? ? ? alert("結(jié)束");
? ? ? ? }
? ? }
? </script>?
2016-04-01
語(yǔ)法:prompt(str1, str2);
參數(shù)說(shuō)明:
str1: 要顯示在消息對(duì)話框中的文本,不可修改
str2:文本框中的內(nèi)容,可以修改
默認(rèn)的地址應(yīng)該設(shè)置在promptly()中的第二個(gè)字符串中
2016-04-01
var address=prompt("http://idcbgp.cn/");改為var address=prompt(”請(qǐng)輸入網(wǎng)址“,"http://idcbgp.cn/");