html表单jquery验证
Posted
技术标签:
【中文标题】html表单jquery验证【英文标题】:html form jquery validation 【发布时间】:2019-02-17 17:27:42 【问题描述】:我已经尝试了很长时间,但我不知道如何让 jquery 验证插件与 html 一起工作,非常感谢您的帮助。 我想这是微不足道的,但我找不到解决方案。
这是我的代码
<html>
<head>
<script src="external/jquery/jquery.js"></script>
<script src="jquery-ui.js"></script>
<link href="jquery-ui.css" rel="stylesheet">
</head>
<body>
<form id="forma">
<p>
<label for="username" id="labelusername">usename</label>
<input type="text" id="username" name="username" />
</p>
<input type="submit" id="save" value="submit" onclick="" />
</form>
</body>
<script>
$().ready(function()
$("#forma").validate(
rules:
username: "required"
,
messages:
username: "please enter"
);
);
</script>
</html>
感谢您的帮助!
【问题讨论】:
您是否在控制台中遇到任何错误? 【参考方案1】:欢迎编码。
我注意到,您缺少 jquery 文档
<!DOCTYPE html>
<html lang="en">
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-validate/1.17.0/jquery.validate.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-validate/1.17.0/additional-methods.min.js"></script>
</head>
<body>
<form id="forma">
<p>
<label for="username" id="labelusername">usename</label>
<input type="text" id="username" name="username" />
</p>
<input type="submit" id="save" value="submit" onclick="" />
</form>
</body>
<script>
$('document').ready(function()
$("#forma").validate(
rules:
username:"required"
,
messages:
username:"please enter"
);
);
</script>
</html>
【讨论】:
以上是关于html表单jquery验证的主要内容,如果未能解决你的问题,请参考以下文章
如何在不通过 jQuery 提交的情况下强制进行 html5 表单验证