2.13.JavaScript--条件语句

<!DOCTYPE HTML>
<html lang="en-US">
<head>
<meta charset="UTF-8">
<title>2.13.JavaScript.条件语句</title>
</head>
<body>
<script type="text/javascript">

/*
//if else语句
if( 100 > 10 ){
document.write("真");
}else{
document.write("假");
}
*/
//

function checkChange(){
var username = document.getElementById("username");//获取到html节点
if( username.value == ""){
alert(
"用户名不能为空");
}
else if( username.value == "admin" || username.value == "xiaozhanga4"){
alert(
"恭喜你," + username.value);
}
else{
alert(
"用户名错误");
}

}

</script>

<form method="post" action="">
<input type="text" name="username" id="username"/>
<input type="submit" value="提交" onclick="checkChange();"/>
</form>


</body>
</html>
posted @ 2012-03-15 17:34  校长阿四  阅读(187)  评论(0编辑  收藏  举报