JQuery 新手:从 JQuery 验证内部调用 Javascript 函数
我的问题与此类似: 从 jquery success 调用 javascript 函数;但我没有使用 AJAX。
很简单,我正在验证一个表单(只是邮政编码)作为 Google 地图网络应用程序的一部分。验证代码是这样的:
$(document).ready(function($)
{
$("#clientInput").validate
({
debug: true,
rules:{zipcode: {required:true, minlength:5, maxlength:10, digits: true}},
messages: {zipcode: {required: "You need to provide at least a zipcode.", minlength: "Please enter at least 5 digits", maxlength: "You've entered too many digits, please re-enter."}},
});
searchlocations();
});
粗体函数调用是对我的阻碍,它是对 Google Map API 函数的调用,但它永远不会被调用。 Google 地图 javascript 在此代码之前加载(尽管它位于单独的文件中),并且在添加验证代码之前,我通过“提交”按钮的 onclick() 事件调用了该函数。
如何在成功验证表单时调用此函数?
蒂亚!
My question is similar to this one: Call javascript function from jquery success; but I'm not using AJAX.
Very simply, I'm validating a form (just the zipcode) as part of a Google Maps web app. The validation code is as such:
$(document).ready(function($)
{
$("#clientInput").validate
({
debug: true,
rules:{zipcode: {required:true, minlength:5, maxlength:10, digits: true}},
messages: {zipcode: {required: "You need to provide at least a zipcode.", minlength: "Please enter at least 5 digits", maxlength: "You've entered too many digits, please re-enter."}},
});
searchlocations();
});
The bold function call is what's stymieing me, it's a call to the Google Map API function but it never gets called. The Google Map javascript is loaded before this code (although it's in a separate file) and before I added the validation code I called the function through the Submit button's onclick() event.
How can I get this function called on successful validation of the form?
TIA!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要将该函数设置为用于验证的
submitHandler
。You need to make the function the
submitHandler
for the validation.查克说得对;不过,这里有一个示例可以提供帮助:
如果您只需要调用 searchLocations,则可以通过直接分配 searchLocations 函数来使其变得更加简单:
Chuck is right on; here's an example to help, though:
If you only need to call searchLocations, you can make it even simpler by just assigning the searchLocations function directly: