gpt4 book ai didi

带有验证插件的 jquery 不工作

转载 作者:太空宇宙 更新时间:2023-11-04 13:06:06 24 4
gpt4 key购买 nike

在花了几个小时试图解决一个看似简单的问题(正在浏览 stackoverflow 问题......)之后,我再次不得不转向 stackoverflow 并提交我的问题......我有一个非常基本的表格只有两个控件:文本输入和提交底部。我正在尝试让 jquery 验证插件工作。这是我的代码:

 <html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>

<script src="//code.jquery.com/jquery-1.11.0.min.js"></script>
<script src="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js" ></script>
<script src="jquery.validate.js"></script>

<script>

$(function () {

$('#frm').validate({

rules: {
txtInput: {
required:"Reuired"
}
},
messages:{
txtInput:"Please enter your first name"
}
});

});

</script>

</head>
<body>
<form id="frm" name="frm" method="post">
<div>
<input id="txtInput" type="text" placeholder="Name" />
</div>
<br />
<input id="btn" type="submit" class="btn btn-danger" value="Submit" />
</form>

</body>
</html>

jquery.validate.js 是 1.11.1 版本

我的理解是,如果我提交带有空白文本输入的表单,我必须收到消息“请输入您的名字”。但是没有任何反应,表单正常提交。我不知道我做错了什么。这个案子相当简单。预先感谢您给我的任何帮助和/或指导。

最佳答案

你能试试这个吗:

 <input id="txtInput" type="text" placeholder="Name"  name="txtInput"/>

请注意,我已将 name 属性添加到 input,还将 required 规则更新为 true 为:

rules: {
txtInput: {
required: true
}
}

DEMO

关于带有验证插件的 jquery 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25121721/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com