在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問(wèn)答/iOS  HTML/ js兩個(gè)if嵌套在一起是如何運(yùn)行的?

js兩個(gè)if嵌套在一起是如何運(yùn)行的?

如這個(gè)登錄驗(yàn)證的例子,兩個(gè)if嵌套在一起是怎么運(yùn)行的?

<!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">賬號(hào):</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">
    //驗(yàn)證登錄
    function checkLogin() {
        if (loginform.username.value != "") {
            if (loginform.password.value != "") {
                return ture
            } else {
                alert('密碼不能為空');
                return false
            }

        } else {
            alert('用戶名不能為空');
            return false
        }
    }
    </script>
</body>

</html>
回答
編輯回答
爛人
st=>start: Start
cond=>condition: 用戶名是否不為空?
cond2=>condition: 密碼是否不為空?
e=>end: alert('用戶名不能為空')
e2=>end: 通過(guò)
e3=>end: alert('密碼不能為空')
st->cond
cond(no)->e
cond(yes)->cond2(yes)->e2
cond(yes)->cond2(no)->e3
2017年10月13日 20:25
編輯回答
安若晴
var username = loginform.username.value != "";
var password = loginform.password.value != "";
if(!username ){
    alert('用戶名不能為空');
}
if(!password){
    alert('密碼不能為空');
}
return username && password;
2018年7月9日 16:02