<form action="" method="POST" class="form1" onsubmit="return do_submit();">
<table class="form1">
<tr><td><label>用户名:</label><input type="text" name="reg[username]" value="<?php echo $data['username'];?>" id="username" class="input-text1"/></td></tr>
<tr><td><label>密码:</label><input type="password" name="reg[pwd]" value="<?php echo $data['pwd'];?>" id="pwd" class="input-text1"/></td></tr>
<tr><td><label>确认密码:</label><input type="password" name="reg[repwd]" value="<?php echo $data['repwd'];?>" id="repwd" class="input-text1"/></td></tr>
<tr><td><label>邮箱:</label><input type="text" name="reg[email]" value="<?=$data['email']?>" id="email" class="input-text1"/></td></tr>
<tr><td><label>性别:</label><input type="radio" name="reg[sex]" />男
<input type="radio" name="reg[sex]" />女</td></tr>
<tr><td><label>QQ:</label><input type="text" name="reg[QQ]" value="<?php echo $data['QQ']?>" id="QQ" class="input-text1"/></td></tr>
<tr><td><label>个人主页:</label><input type="text" name="reg[homepage]" value="<?php echo $data['homepage'];?>" id="homepage" class="input-text1"/></td></tr>
<tr><td><label>生日:</label><input type="text" name="reg[birth]" value="<?php echo $data['birth'];?>" id="birth" class="input-text1"/></td></tr>
<tr><td><label>现住城市:</label><input type="text" name="reg[city]" value="<?php echo $data['city'];?>" id="city" class="input-text1"/></td></tr>
<tr><td><label>家庭住址:</label><input type="text" name="reg[addr]" value="<?php echo $data['addr'];?>" id="adr" class="input-text1"/></td></tr>
<tr><td>
<div class="input-code">
<input type="hidden" name="act" value="register"/>
<input type="submit" value="立即注册" />
<input type="reset" value="重新填写" />
</div>
</td></tr>
</table>
</form>
/*-------省略部分代码---------*/
<script language="javascript">
String.prototype.trim = function() {return this.replace(/^\s+|\s+$/g, '');}
function do_submit() {
var username = document.getElementById('username');
if ( username.value.trim() == '' ) {
window.alert('用户名尚未填写。');
username.className = 'input-error'; //设置CSS样式
username.focus(); //聚焦
username.value = '';
return false; //阻止表单提交
}
var pwd = document.getElementById('pwd');
if ( pwd.value.trim() == '' ) {
window.alert('密码尚未填写。');
pwd.className = 'input-error';
pwd.focus();
pwd.value = '';
return false;
}
//window.alert(passwd.value.trim().length);
if ( pwd.value.trim().length < 6 ) {
window.alert('密码不能少于六位!');
pwd.className = 'input-error';
pwd.focus();
pwd.value = '';
return false;
}
var repwd = document.getElementById('repwd');
if ( repwd.value.trim() == '' ) {
window.alert('重复密码尚未填写。');
repwd.className = 'input-error';
repwd.focus();
repwd.value = '';
return false;
} else {
if ( pwd.value.trim() != repwd.value.trim() ) {
window.alert('两次密码不一致!');
return false;
}
}
var email = document.getElementById('email');
if ( email.value.trim() == '' ) {
window.alert('电子邮件尚未填写。');
email.className = 'input-error';
email.focus();
email.value = '';
return false;
}
</script>
------解决方案--------------------
<form action="" method="POST" class="form1" name="myform" onsubmit=return do_submit();">
<input type="submit" value="立即注册" onClick="return do_submit();" />
==》
<input type="submit" value="立即注册"/>
------解决方案--------------------
</script> 结尾少个}