gpt4 book ai didi

jQuery 如果 myform.valid() 为 true 则触发另一个 jQuery 函数?

转载 作者:行者123 更新时间:2023-12-03 22:59:55 25 4
gpt4 key购买 nike

我有一个 jQuery 函数,仅当表单验证为 true 时我才想执行该函数
我的验证和其他 jQuery 工作正常。
现在的问题是验证和其他功能同时执行。
仅当表单验证为真时,我才想运行其他函数。这是我的脚本

<script>
$(document).ready(function () {
$.validator.addClassRules({
fileName: {
required: true
}
});
$("#myform").validate();
if ($("#myform").valid()) {
$(function () {
$('#myform').submit(function () {
var cboxes = ($('input:checkbox:checked').filter(":checked").length);
var nboxes = ($(":checkbox:not(:checked)").length);
if ((cboxes > 0) && (nboxes > 0)) {
confirm('You have Checked only few locations among the List. \n Are you sure, you do not want to Prescribe from the other locations? ');
} else if (cboxes == 0) {
alert('Please select atleast One Address \n Where you would prefer to prescribe from.');
return false;
}
else {
return true;
}
});
});
}
});
</script>

请告诉我如何完成这项工作?

最佳答案

如果您使用 jQuery 验证插件,则 valid()方法返回一个 bool 值来指示表单验证是否成功,因此您可以这样做:

if ($("#myform").valid()) {
CallSomeOtherFunction();
}

关于jQuery 如果 myform.valid() 为 true 则触发另一个 jQuery 函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7675053/

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