1

我正在开发由另一个程序员开发的网站。在 db 中输入数据之前,有一个表单具有 javascript 验证。但我真的不明白为什么我会收到此警报。请参见下面的代码:

function save(){
  if (echeck(document.getElementById('email').value)==false){
    document.getElementById('email').focus();
  }else if(document.getElementById('fullname').value==''){
    alert("Full name is required");
    document.getElementById('fullname').focus();
  }else if(document.getElementById('handphone').value==''){
    alert("HP number is required");
    document.getElementById('handphone').focus();
  }else if(document.getElementById('bank_name').value==''){
    alert("Bank Account Name is required");
    document.getElementById('bank_name').focus();
  }else if(document.getElementById('bank_number').value==''){
    alert("Bank Account Number is required");
    document.getElementById('bank_number').focus();
  }else if(document.getElementById('code').value==''){
    alert("Captcha Code cannot be blank");
    document.getElementById('code').focus();
  }else{
    $.post("<?php echo base_url(); ?>index.php/misterjudi/register/", {
      email:document.getElementById('email').value,
      fullname:document.getElementById('fullname').value,
      handphone:document.getElementById('handphone').value,
      bank:document.getElementById('bank').value,
      bank_name:document.getElementById('bank_name').value,
      bank_number:document.getElementById('bank_number').value,
    },
    function(data){
      alert("Successfully registered");
      location.href="<?php echo base_url(); ?>";
    });
  }
}

因此,如果我理解正确,它会检查字段是否不为空。即使我填写了所有字段,我仍然收到类似('全名')的警报。

提前感谢您的帮助。

这是HTML代码:

<table style="border:0px solid #CCC; width:100%;">
  <tr>
    <td style="padding-bottom:10px; width:180px;">Email
      <span style="color:#F00;">*</span></td><td style="padding-left:20px; padding-bottom:10px;">
      <input id="email" type="text" name="email" onblur="check_email(this.value);" />
    </td>
  </tr>
  <tr>
    <td style="padding-bottom:10px;">Nama <span style="color:#F00;">*</span>
    </td>
    <td style="padding-left:20px; padding-bottom:10px;">
      <input id="fullname" type="text" name="fullname" />
    </td>
  </tr>
  <tr>
    <td style="padding-bottom:10px;">No HP <span style="color:#F00;">*</span>
    </td>
    <td style="padding-left:20px; padding-bottom:10px;">
      <input id="handphone" type="text" name="handphone" />
    </td>
  </tr>
  <tr>
    <td style="padding-bottom:10px;">Nama Bank <span style="color:#F00;">*</span></td>
    <td style="padding-left:20px; padding-bottom:10px;">
      <select name="bank" id="bank">
        <?php $data=$this->dubol_model->get_bank(); ?>
        <?php for($i=0;$i<count($data);$i++){ ?>
        <option value="<?php echo $data[$i]['BankCode']; ?>">
          <?php echo $data[$i]['BankName']; ?></option>
          <?php } ?>
      </select>
    </td>
  </tr>
  <tr>
    <td style="padding-bottom:10px;">Nama Rekening <span style="color:#F00;">*</span></td>
    <td style="padding-left:20px; padding-bottom:10px;"><input id="bank_name" type="text" name="bank_account_name" /></td>
  </tr>
  <tr>
    <td style="padding-bottom:10px;">Nomor Rekening <span style="color:#F00;">*</span></td>
    <td style="padding-left:20px; padding-bottom:10px;">
      <input id="bank_number" type="text" name="bank_account_number" />
    </td>
  </tr>
  <tr>
    <td colspan="2">
      <div style="width: 430px; padding-top:20px; padding-bottom:20px; float: left; height:90px; background-color:#FFF; border:1px solid #CCC;">
        <img id="siimage" align="left" style="padding-right: 5px; border: 0" src="<?php echo base_url(); ?>/captcha/securimage_show.php?sid=<?php echo md5(time()) ?>" />
        <script type="text/javascript">
          AC_FL_RunContent( 'codebase','http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0','width','19','height','19','id','SecurImage_as3','align','middle','src','<?php echo base_url(); ?>/captcha/securimage_play?audio=<?php echo base_url(); ?>/captcha/securimage_play.php&bgColor1=#777&bgColor2=#fff&iconColor=#000&roundedCorner=5','quality','high','bgcolor','#ffffff','name','SecurImage_as3','allowscriptaccess','sameDomain','allowfullscreen','false','pluginspage','http://www.macromedia.com/go/getflashplayer','movie','<?php echo base_url(); ?>/captcha/securimage_play?audio=<?php echo base_url(); ?>/captcha/securimage_play.php&bgColor1=#777&bgColor2=#fff&iconColor=#000&roundedCorner=5' ); //end AC code
        </script>
        <noscript>
          <object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width="19" height="19" id="SecurImage_as3" align="middle">
            <param name="allowScriptAccess" value="sameDomain" />
            <param name="allowFullScreen" value="false" />
            <param name="movie" value="<?php echo base_url(); ?>/captcha/securimage_play.swf?audio=<?php echo base_url(); ?>/captcha/securimage_play.php&bgColor1=#777&bgColor2=#fff&iconColor=#000&roundedCorner=5" />
            <param name="quality" value="high" />
            <param name="bgcolor" value="#ffffff" />
            <embed src="<?php echo base_url(); ?>/captcha/securimage_play.swf?audio=<?php echo base_url(); ?>/captcha/securimage_play.php&bgColor1=#777&bgColor2=#fff&iconColor=#000&roundedCorner=5" quality="high" bgcolor="#ffffff" width="19" height="19" name="SecurImage_as3" align="middle" allowScriptAccess="sameDomain" allowFullScreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />
          </object>
        </noscript><br />
        <!-- pass a session id to the query string of the script to prevent ie caching -->
        <a tabindex="-1" style="border-style: none" href="#" title="Refresh Image" onClick="document.getElementById('siimage').src = '<?php echo base_url(); ?>/captcha/securimage_show.php?sid=' + Math.random(); return false"><img src="<?php echo base_url(); ?>/captcha/images/refresh.gif" alt="Reload Image" border="0" onClick="this.blur()" align="bottom" /></a>
      </div>
    </td>
  </tr>
  <tr>
    <td style="padding-top:10px;">Code <span style="color:#F00;">*</span></td>
    <td style="padding-top:10px;">
      <input id="code" type="text" name="code" size="12" />
    </td>
  </tr>
  <tr>
    <td colspan="2" style="padding-top:20px;">
      <input type="button" value="    Close    " onclick="$('#register').animate({  height: 'toggle', opacity: 'toggle'}, 1000);" />
      <input type="button" value="Register" onclick="save();" />
    </td>
  </tr>
</table>
4

1 回答 1

0

类型:console.log(document.getElementById('fullname').value, document.getElementById('fullname').value === ''); 在'alert("Fullname is required");'行之前 调试。

此代码将在您的 Web 检查器控制台中打印该输入的值,它是否等于空字符串。我想它会帮助你理解这个问题。

于 2012-11-24T02:18:53.813 回答