js判断input是否为空

<SCRIPT LANGUAGE="JavaScript">
function jj(){
if(document.getElementByIdx_x_x('name').value==''){
     alert('用户名不能为空');
     return false;
}
if(document.getElementByIdx_x_x('phone').value==''){
     alert('电话不能为空');
     return false;
}
if(document.getElementByIdx_x_x('password').value==''){
     alert('密码不能为空');
     return false;
}
if(document.getElementByIdx_x_x('password').value != document.getElementByIdx_x_x('password2').value){
     alert('两次输入的密码不一样');
     return false;
}
if(!document.getElementByIdx_x_x('agreement').checked ==true){
     alert('你还没有接受用户协议');
     return false;
}
}
function hh(x,y){
if(document.getElementByIdx_x_x(x).value ==''){
     document.getElementByIdx_x_x(y).innerHTML='带*号的为必填,请不要留下空格';
}
}
</SCRIPT>
<form action="" method="post" οnsubmit="return jj()">
<table width="100%" border="0">
       <tr>
              <td width="40%" align="right">用户名:</td>
              <td width="60%"><input type="text" size="25" id="name" name="user_name" οnblur="hh('name','name_notice')" />
              <span id="name_notice" style="color:#FF0000">*</span></td>      
       </tr>
       <tr>
              <td width="40%" align="right">电话:</td>
              <td width="60%"><input type="text" size="25" id="phone" name="user_phone" οnblur="hh('phone','phone_notice')" />
              <span id="name_notice" style="color:#FF0000">*</span></td>      
       </tr>
       <tr>
              <td width="40%" align="right">密码:</td>
              <td width="60%"><input type="password" size="25" id="password" name="pwd" οnblur="hh('password','password_notice')" />
              <span id="password_notice" style="color:#FF0000">*</span></td>
       </tr>
       <tr>
              <td width="40%" align="right">重复密码:</td>
              <td width="60%"><input type="password" size="25" id="password2" name="pwd2" οnblur="hh('password2','password_notice')" />
              <span id="password_notice2" style="color:#FF0000">*</span></td>
       </tr>
       <tr>
          <td align="center" colspan="2"><label>
              <input name="agreement" type="checkbox" id='agreement' οnblur="hh('agreement','agreement_notice')"/>
              我已看过并接受《<a href="article.php?cat_id=-1" style="color:blue" target="_blank">用户协议</a>》</label></td>
       </tr>
       <tr>
              <td align="center" colspan="2"><input type="submit" value="注册" name="a" /></td>
       </tr>
</table>
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值