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