>  기사  >  백엔드 개발  >  form 提交 验证问题

form 提交 验证问题

WBOY
WBOY원래의
2016-06-23 14:24:46814검색

function url js php

比如
" method="GET" onsubmit="add()">
   input->get('call');?>" />

 



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

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

回复讨论(解决方案)

<form action="<?php echo base_url('heli/add'); ?>" method="GET" onsubmit="return 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;    }    return true;  }</script>

基本上你已经写出来了, 记得要包含jquery的库
否则要用document.getElementById('')这样获取值

<form action="<?php echo base_url('heli/add'); ?>" method="GET" onsubmit="return 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;    }    return true;  }</script>

基本上你已经写出来了, 记得要包含jquery的库
否则要用document.getElementById('')这样获取值


---------------------------------------
我在提交的时候,还是没有验证 直接跳到后台了

<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的原因。

<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的原因。

-----------------------------------------------------
谢谢 大虾大力帮助 
jquery 引入了 js 没有问题:
因为我用 

去获取值都可以的,所以js 和jquery 都没有问题,只是在form 表单提交时候 不进过js 验证

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

성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.