效果如图所示:今天共享给你们 练习html
转载注明出处www.gjrencai.comjava
///////////////////////代码以下///////////////////////////正则表达式
<htmlhtmljavahtmlhtml>
<head>
<meta http-equiv="content-type"
content="text/; charset=utf-8">
<script type="text/script">
function $(a) {
return document.getElementById(a);
}ssh
function checkUsername(){
// 验证用户名
var username=$("username").value;
// 正则表达式Regular Expression
var tmp =
username.replace(/^\s+/, "")
.replace(/\s+$/, "");
if(tmp.length == 0){
//alert("用户名不能为空");
$("username_span").style.display="block";
return false;
} else {
$("username_span").style.display="none";
return true;
}
}学习
function checkPassword() {
var password = $("password").value;
if(password.length < 6){
$("password_span").style.display
="block";
return false;
} else {
$("password_span").style.display
="none";
return true;
}
}网站
function checkEmail() {
var email = $("email").value;
// test方法返回真表示字符串符合正则表达式
if(/^\w+@\w+\.(com|org|cn)$/.test(email)){
$("email_span").style.display="none";
return true;
} else {
$("email_span").style.display="block";
return false;
}
}ui
window.onload = function(){
var bt = $("bt");
bt.onclick = function(){
if(! checkUsername()) {
return;
}
if(! checkPassword()) {
return;
}
if( !checkEmail()){
return;
}
$("form").submit();
};
$("username").onblur = checkUsername;
$("password").onblur = checkPassword;
$("email").onblur = checkEmail;
}
</script>
</head>
<body>
<form action="success." id="form">
用户名:
<input type="text" id="username"/>
<span id="username_span" style="display:none;color:red">用户名不能为空</span>
<br/>
密码:
<input type="password" id="password"/>
<span id="password_span" style="display:none;color:red">密码必须大于等于6</span>
<br/>
确认密码:
<input type="password" id="password2"/>
<br/>
邮件:
<input type="text" id="email"/>
<span id="email_span" style="display:none;color:red">
邮件格式不合法
</span>
<br/>
婚否:
是<input type="radio" name="isMarried"/>
否<input type="radio" name="isMarried"/>
<br/>
爱好:
<br/>
游泳
<input type="checkbox" name="favs"/>
唱歌
<input type="checkbox" name="favs"/>
跳舞
<input type="checkbox" name="favs"/>
游戏
<input type="checkbox" name="favs"/>spa
<input type="button" value="注册" id="bt"/>orm
</form>
</body>
</>htm
【Gjava人才网】www.gjrencai.com 帮助你们一块儿学习java网站内容所有为 北京培训机构代码 笔记,项目等新手进入网站,先看新手学习时序图,安排好时间学习java时间与过程,再去看21天学java教程,id=16315天学ssh 笔记内容等。id=193开发人员必备的20个Java功能代码