jQuery 验证参数
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您只需引用函数本身,就会为您传递元素:
startTimeRequired() (如果括号存在)告诉 javascript 然后运行该函数,这不是您想要的。您想要告诉所需的事件处理程序在 startTimeRequired 处抛出“事件”。
You just reference the function itself, element is passed for you:
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.