日期:2014-05-17  浏览次数:20464 次

form 提交 验证问题
比如
<form action="<?php echo base_url('heli/add'); ?>" method="GET" onsubmit="add()">
   <input name="call" name="call" type="text" value="<?php echo  $this->input->get('call');?>" />

 <td><input type="submit" value="添加"  /></td>
</form>


<script type="text/javascript">
  function add(){
    var call= $("#call").attr("value");
    if(call== ""){
      alert("NO");
      return false;
    }
  }
  
</script>

---------------------------------------------------------
我的问题是,这样实现提交form 表单的时候先js 验证是否为空,然后在跳到后台去验证。
function url js php

------解决方案--------------------

<form action="test3.php" method="GET" onsubmit="return add();">
   <input name="call" id="call" type="text" value=""/>
 <td><input type="submit" value="添加"  /></td>
</form>
 
 
<script type="text/javascript">
  function add(){
    var call= document.getElementById('call').value;
    if(call== ""){
      alert("NO");
      return false;
    }
    return true;
  }
</script>
好人做到底吧,帮你调试一下。
你没有检查而直接提交是因为JS有错误,有可能是因为没有引入jquery的原因。

------解决方案--------------------
你input里面有两个name属性哦,应该是一个id一个name!你改下看下能不能行。