jquery实现表单验证并阻止非法提交
作者:hebedich 时间:2023-07-02 05:31:28
代码检测textarea内填写的长度,未填写时提示需要重新填写,少于15字符时提示需要长于15字符,成功时显示所填写建议。
<script type="text/javascript">
//jQuery代码
function confirm()
{
if($("#advice").val().length == 0)
{
alert("We can't see your advice. Maybe you should fill the form first.");
$("#advice").focus();
return false;
}
else if($("#advice").val().length <= 15)
{
alert("Your advice should longer than 15 letters.");
$("#advice").focus();
return false;
}
else
{
alert("Thank you for your advice! You will get out reply in 24 hours for advice:\n"+$("#advice").val());
return true;
}
}
</script>
<form action="" method="post" onSubmit="return confirm();" >
<textarea id="advice" rows="20" cols="50"placeholder="Give us some advice?"></textarea>
<input type="submit"value="Thank you"/>
</form>
>关键点
1.必须要有onSubmit="return confirm();" return 这个词,不可缺少。
2.自行完整的网页结构。
以上所述就是本文的全部内容了,希望大家能够喜欢。
标签:jquery,表单验证
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Pytorch1.5.1版本安装的方法步骤
2021-02-07 00:57:09
![](https://img.aspxhome.com/file/2023/5/95235_0s.png)
PHP登录验证功能示例【用户名、密码、验证码、数据库、已登陆验证、自动登录和注销登录等】
2023-11-14 23:24:02
![](https://img.aspxhome.com/file/2023/5/86925_0s.png)
Python中逗号的三种作用实例分析
2021-12-24 23:52:33
利用Python制作百度图片下载器
2021-02-25 09:17:55
![](https://img.aspxhome.com/file/2023/9/117269_0s.gif)
python 利用Pyinstaller打包Web项目
2021-11-25 12:22:36
![](https://img.aspxhome.com/file/2023/9/124999_0s.png)
关于Python 解决Python3.9 pandas.read_excel(‘xxx.xlsx‘)报错的问题
2021-11-05 01:05:28
![](https://img.aspxhome.com/file/2023/6/80766_0s.png)
微信小程序开发之实现心情记事本
2024-04-18 09:45:20
![](https://img.aspxhome.com/file/2023/0/136280_0s.jpg)
Python计算双重差分模型DID及其对应P值使用详解
2022-08-06 21:07:53
![](https://img.aspxhome.com/file/2023/5/68335_0s.jpg)
Django实现CAS+OAuth2的方法示例
2023-01-26 17:32:46
Python判断三段线能否构成三角形的代码
2023-01-21 19:44:25
python标准库学习之sys模块详解
2021-08-02 02:25:19
![](https://img.aspxhome.com/file/2023/4/98984_0s.jpg)
java配置数据库连接池的方法步骤
2024-01-17 21:00:32
php实现的三个常用加密解密功能函数示例
2023-07-20 06:25:52
![](https://img.aspxhome.com/file/2023/4/55424_0s.jpg)
Python实现AI自动抠图实例解析
2021-12-25 11:04:22
![](https://img.aspxhome.com/file/2023/2/125152_0s.png)
解决windows下python3使用multiprocessing.Pool出现的问题
2021-11-03 23:34:37
![](https://img.aspxhome.com/file/2023/3/109573_0s.jpg)
django中使用原生sql语句的方法步骤
2023-06-29 16:36:07
PHP结构型模式之外观模式
2023-05-25 11:43:14
python 装饰器的使用示例
2021-05-15 00:52:09
mysql 5.7以上版本下载及安装图文教程
2024-01-27 21:53:56
![](https://img.aspxhome.com/file/2023/4/118444_0s.png)
python 双循环遍历list 变量判断代码
2021-02-10 12:38:12