gpt4 book ai didi

c# - 将 jQuery 验证插件用于 div 而不是表单?

转载 作者:行者123 更新时间:2023-11-30 17:55:33 24 4
gpt4 key购买 nike

注意:我提到了这些问题Qn1 , Qn2在问这个之前。但老实说,答案不起作用。请提出解决方案..我正在使用 jquery 验证插件对我的输入字段进行验证。当所有标签都保存在表单标签内并在 jquery 中访问它时,我的代码工作正常,$("#formID").validate() --> 这工作正常......但是我想为 div 而不是表单实现相同的效果。

我这样试过:$("#divID").validate() 但它不起作用...

下面是我的代码。请看一下并告诉我如何为 div 实现它。

 <script type="text/javascript">
$(document).ready(function () {
$("#content").validate({
onfocusout: true,
rules: {
fullname:
{
lettersonly: true,
required: true
},
age:
{
required: true,
number: true,
min: 20,
max:98,
nowhitespace:true
}
},
messages: {
fullname: "Please specify your name.",
age:"Please enter your correct age."
}
});
});
</script>
<div id="content">
<p>
<label for="fullname">Full name:</label>
<input type="text" name="fullname" id="fullname" /><br />
<label for="age">Age</label>
<input type="text" name="age" />
</p>
<p>
<button id="submit" value="">Search User</button>
</p>
</div>

最佳答案

Quote OP: "NOTE: I referred these questions Qn1 , Qn2 before asking this . But honestly the answers are not working."

不正确,the accepted answerQn2工作完美:

The validation plugin is (currently) designed to work on a <form>, and only on a <form>. You can also note that all of the plugin documentation references a form, not any other generic container.

必须使用 form带有 jQ​​uery Validate 插件的元素。对此没有解决方法。

但是,如果您只是想验证一些输入而不实际提交 form ,有很多可行的解决方案。 示例:http://jsfiddle.net/GmQ5d/

Full Documentation

关于c# - 将 jQuery 验证插件用于 div 而不是表单?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14981539/

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