JQuery form表单提交前验证单选框是否选中、删除记录时验证经验总结(整理)
先上三张效果图:

这些功能在Java Web开发中可能是经常需要的,虽然很简单却使很实用的功能,这里记录下以免忘记。
1. 先说表单提交前验证:后台经常用到(这里是提交后统一验证,及时验证请参考我另一篇文章
http://blog.csdn.net/jianzhonghao/article/details/52503431)
1.1 通过submit 按钮提交后 会根据form的属性action=“路径”来跳转到相应的路径,这时,给form添加一个 onsubmit =”return check()” 属性, check()使我们要写的验证函数,如下图:
<form action="路径" onsubmit="return check()" method="POST">
1.2 check()函数如下(验证姓名是否填写 与 单选框性别是否选中) $(‘#notice') 的话,随便写个div加个id属性就好了
<script type="text/javascript">
function check(){
var name = $('#name').val().trim();
var gender=$('input:radio[name="gender"]:checked').val();
if(!name){
$('#notice').text('客服名称不能为空!').show();
return false;
}else if(!gender){
$('#notice').text('请选择客服性别!').show();
return false;
}
else{
return true;
}
}
</script>
<div id="notice" style="font-size: 30px;color:red;margin-top: 15px;" ></div>1.3最后说一下删除时,确认是否删除的问题
<input type="image" src="删除图标的路径" title="删除" onclick="{if(confirm('确定删除吗?')){javascript:document:delfrom_${ServerInfo.id };return true;}return false;}">
分开写实际就是
if(confirm('确定删除吗?')){
{javascript:document:delfrom_${ServerInfo.id };
return true;
}
return false; 相关推荐
wcqwcq 2020-07-04
TONIYH 2020-06-11
yhginny 2020-04-20
nicepainkiller 2020-05-12
Lius 2020-05-05
longshengguoji 2020-02-13
ajaxtony 2020-02-03
HSdiana 2019-12-15
taiyanghua 2019-12-02
sunnyishere 2014-01-22
86580599 2019-09-23
shumark 2014-05-29
爱好HtmlCssJs 2019-10-28
shumark 2014-07-07
AngelicaA 2015-03-14
81751330 2015-03-10
kentrl 2016-05-03
乔乔 2016-04-30
Qc 2020-07-19