jQuery 验证参数

发布于 2024-09-02 08:48:12 字数 159 浏览 2 评论 0原文

jQuery 验证插件具有所需规则的“element”参数。我知道如何将它用于内联函数,但是如果我想将它传递给外联 JS 函数怎么办?我试过这个:

规则:{ 开始时间:{ 必需:startTimeRequired(元素) },

但没有成功。

jQuery Validation plugin has "element" argument for required rule. I know how to use it for inline functions but what if I want to pass it to out-of-line JS function? I tried this:

rules: {
startHours: {
required: startTimeRequired(element)
},

but it didn't work.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

别念他 2024-09-09 08:48:12

您只需引用函数本身,就会为您传递元素:

rules: { startHours: { required: startTimeRequired },

startTimeRequired() (如果括号存在)告诉 javascript 然后运行该函数,这不是您想要的。您想要告诉所需的事件处理程序在 startTimeRequired 处抛出“事件”。

You just reference the function itself, element is passed for you:

rules: { startHours: { required: startTimeRequired },

startTimeRequired() (if the parens are there) tells javascript to run the function then, which isn't what you want. You want to tell the required event handler to throw 'event' at startTimeRequired.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文