亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

js兩個if嵌套在一起是如何運行的?

js兩個if嵌套在一起是如何運行的?

素胚勾勒不出你 2019-02-12 17:19:12
如這個登錄驗證的例子,兩個if嵌套在一起是怎么運行的?<!DOCTYPE html><html><head>    <title>login</title>    <meta charset="utf-8"></head><body>    <form id="loginform" name='loginform' onsubmit="return checkLogin()">        <div>            <label for="username">賬號:</label>            <input type="text" id="username" name="username">        </div>        <div>            <label for="password">密碼:</label>            <input type="password" id="password" name="password">        </div>        <input type="submit" value="登錄">    </form>    <script type="text/javascript">    //驗證登錄    function checkLogin() {        if (loginform.username.value != "") {            if (loginform.password.value != "") {                return ture            } else {                alert('密碼不能為空');                return false            }        } else {            alert('用戶名不能為空');            return false        }    }    </script></body></html>
查看完整描述

2 回答

?
慕田峪9158850

TA貢獻1794條經驗 獲得超8個贊

https://img1.sycdn.imooc.com//5c7240410001bfc505720432.jpg

查看完整回答
反對 回復 2019-02-24
?
慕標5832272

TA貢獻1966條經驗 獲得超4個贊

var username = loginform.username.value != "";

var password = loginform.password.value != "";

if(!username ){

    alert('用戶名不能為空');

}

if(!password){

    alert('密碼不能為空');

}

return username && password;


查看完整回答
反對 回復 2019-02-24
  • 2 回答
  • 0 關注
  • 2083 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號