課程
/前端開發
/JavaScript
/JavaScript入門篇
如果我輸入的網址為空,要使彈出信息顯示為‘再見’如何寫代碼?
2016-07-29
源自:JavaScript入門篇 2-7
正在回答
function openWindow(){
? ? ? if(confirm("是否打開")){
? ? ? ? ? ? var site = prompt("輸入打開的網址","http://www.xianlaiwan.cn").trim();
? ? ? ? ? ? if(site != "")
? ? ? ? ? ? ? ? ? ? window.open(site,'_blank','width=400,height=500,menubar=no,toolbar=no');
? ? ? ? ? ? else ? ??
? ? ? ? ? ? ? ? ? ? alert("再見");? ? ? ??
? ? }
}
Twuof_1997 提問者
? <script type="text/javascript"> ?
? ? function openWindow(){
? ?//新窗口打開時彈出確認框,是否打開
? ? var message=confirm("是否要打開對話框!");
? ? if(message==true){
? ? ? ? var win=prompt("請輸入網址","http://www.xianlaiwan.cn");
? ? ? ? if (win!=""){
? ? ? ? window.open( win , '_blank','width=400','height=500','menubar=no','toolbar=no') ? ? ?
? ? ? ? }
? ? ? ? else{
? ? ? ? ?alert("您輸入的網址有誤,請重新輸入!");
? ? else{
? ? ? ? alert("網頁打開失敗!")
? </script>?
將 ?if(zhi!=null)修改成if(zhi!="") ? ??
? ? ? ? ? ? if(site != ""){
????????????????????window.open(site,'_blank','width=400,height=500,menubar=no,toolbar=no');
?????????????}else?????
????????????????????alert("再見");
? ? ? ? ?????}
<!DOCTYPE html>
<html>
?<head>
? <title> new document </title> ?
? <meta http-equiv="Content-Type" content="text/html; charset=gbk"/> ??
? function openWindow(){
? ? ? var dk=confirm("是否打開");
? ? ? if(dk == true){
? ? ? ? ? var sr=prompt('輸入網址','//www.xianlaiwan.cn/');
? ? ? }
? ? ? else(sr == null){
? ? ? ? ? alert("88")
? ? ? else{
? ? ? ? ? alert("2")
? ? ??
? ??
?</head>?
?<body>?
?<input type="button" value="新窗口打開網站" onclick="openWindow()" />?
?</body>
</html>
舉報
JavaScript做為一名Web工程師的必備技術,本教程讓您快速入門
3 回答為什么我的結果顯示不出來呀?不彈出網頁。。代碼如下。。
1 回答網址打不開,另外請問如果想要打開隨意輸入的一個網址該如何書寫代碼
1 回答如何判斷輸入地址為空,prompt的str2如何獲取
1 回答為什么輸入網址的時候,如果把默認的網址清空點確定或者是點取消不會彈出來警告“請輸入網址!”
1 回答請問,為什么輸入網址為空時,沒有跳出“您未輸入網址”的消息框
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號-11 京公網安備11010802030151號
購課補貼聯系客服咨詢優惠詳情
慕課網APP您的移動學習伙伴
掃描二維碼關注慕課網微信公眾號
2016-07-29
function openWindow(){
? ? ? if(confirm("是否打開")){
? ? ? ? ? ? var site = prompt("輸入打開的網址","http://www.xianlaiwan.cn").trim();
? ? ? ? ? ? if(site != "")
? ? ? ? ? ? ? ? ? ? window.open(site,'_blank','width=400,height=500,menubar=no,toolbar=no');
? ? ? ? ? ? else ? ??
? ? ? ? ? ? ? ? ? ? alert("再見");? ? ? ??
? ? }
}
2016-08-31
? <script type="text/javascript"> ?
? ? function openWindow(){
? ?//新窗口打開時彈出確認框,是否打開
? ? var message=confirm("是否要打開對話框!");
? ? if(message==true){
? ? ? ? var win=prompt("請輸入網址","http://www.xianlaiwan.cn");
? ? ? ? if (win!=""){
? ? ? ? window.open( win , '_blank','width=400','height=500','menubar=no','toolbar=no') ? ? ?
? ? ? ? }
? ? ? ? else{
? ? ? ? ?alert("您輸入的網址有誤,請重新輸入!");
? ? ? ? }
? ? }
? ? else{
? ? ? ? alert("網頁打開失敗!")
? ? }
? ? }
? </script>?
將 ?if(zhi!=null)修改成if(zhi!="") ? ??
2016-07-29
function openWindow(){
? ? ? if(confirm("是否打開")){
? ? ? ? ? ? var site = prompt("輸入打開的網址","http://www.xianlaiwan.cn").trim();
? ? ? ? ? ? if(site != ""){
????????????????????window.open(site,'_blank','width=400,height=500,menubar=no,toolbar=no');
?????????????}else?????
????????????????????alert("再見");
? ? ? ? ?????}
? ? }
}
2016-07-29
<!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 dk=confirm("是否打開");
? ? ? if(dk == true){
? ? ? ? ? var sr=prompt('輸入網址','//www.xianlaiwan.cn/');
? ? ? }
? ? ? else(sr == null){
? ? ? ? ? alert("88")
? ? ? }
? ? ? else{
? ? ? ? ? alert("2")
? ? ? }
? ? ??
? ? ??
? ? ??
? ? ? }
? ??
? </script>?
?</head>?
?<body>?
?<input type="button" value="新窗口打開網站" onclick="openWindow()" />?
?</body>
</html>