由IFrame外部的按钮提交时,jQuery验证未运行 [英] JQuery validation not running when submitted by a button from outside of IFrame

查看:94
本文介绍了由IFrame外部的按钮提交时,jQuery验证未运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用JQuery UI对话框托管IFrame内部的表单.我通过致电...来保存表格.

I am using JQuery UI dialog to host a form that is inside of an IFrame. I am saving the form by calling...

$(myIframe).contents().find('form').submit()

...从对话框的保存按钮中.

...from the dialogs save button.

这将提交表单,但似乎没有调用验证(我正在使用JQuery非侵入式验证).如果我在IFrame中放置一个提交按钮,它就可以正常工作,因此我知道验证逻辑是正确的.

This will submit the form, but it doesn't seem to call the validation (I'm using JQuery unobtrusive validation). If I place a submit button inside the IFrame it works just fine, so I know the validation logic is correct.

如何使验证正常运行?

推荐答案

与其直接从父窗口中调用jquery Submit函数,不如在IFrame内部调用一个方法来调用Submit方法.

Instead of calling the jquery submit function directly from the parent window, call a method inside of the IFrame that calls the submit method.

父窗口...

<script type="text/javascript">
    $(function () {
        $('#btnSubmit').click(function () {
            myFrame.submitForm();
        });
    });
</script>

子窗口...

<script type="text/javascript">
    function submitForm() {
        $('form').submit();
    }
</script>

这篇关于由IFrame外部的按钮提交时,jQuery验证未运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆