方法一:JS判断提交
js函数
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
function checkUser(){ var result = document.getElementById( "userid" ).value; var password = document.getElementById( "userpassid" ).value; if (result == "" ){ return false ; } if (password == "" ){ alert( "密码不能为空" ); return false ; } else { return true ; } } |
form表单
1
2
3
4
5
|
< form id = "formid" name = "myform" method = 'post' onsubmit = "return checkUser();" > < input type = "text" value = "" class = "text2" name = "username" id = "userid" /></ td > < input type = "password" value = "" class = "text2" name = "userpass" id = "userpassid" /></ td > < input type = "submit" value = "" class = "btn2" /> </ form > |
方法二:
1
2
3
4
5
6
7
8
9
10
11
12
13
|
function checkUser(){ var result = document.getElementById( "userid" ).value; var password = document.getElementById( "passid" ).value; if (!result){ alert( "用户名不能为空" ); return false ; } if (!password){ alert( "密码不能为空" ); return false ; } document.getElementById( "formid" ).submit(); } |
form表格的写法,需要写id
1
|
< form id = "formid" method = 'post' > |
button按钮的写法如下:
1
|
< input type = "button" value = "" class = "btn2" onclick = "checkUser();" /> |
© 版权声明
文章版权归作者所有,未经允许请勿转载。