21,886
社区成员
发帖
与我相关
我的任务
分享
<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="<?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('')这样获取值