使用上的JavaScript父文档jQuery的AJAX加载后不工作 [英] Javascript not working after jQuery ajax loads on parent document

查看:107
本文介绍了使用上的JavaScript父文档jQuery的AJAX加载后不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在一个上下观点,我想上传一张图片(在一个目标的iFrame)槽生效的形式(使用jQuery-验证)。之后,该上传的图片中的iFrame的PHP脚本重新加载主文件刷新图像列表制作一个Ajax负载:

In a top-bottom view, I'm trying to upload an image (in a target iFrame) trough a validated form (using jQuery-validate). After that the iFrame's PHP script that upload the image reloads the parent document to refresh the images list making an ajax load:

$('#content', window.parent.document).load(...);

在此之后,父文档的JavaScript标记之间code没有工作,所以有效的方式失败,当我提交表单再只是带我去的索引。

After that, the parent document javascript code between tags doesn't work, so validated forms fails and when I submit the form again just take me to index.

任何一个可以帮我个忙?

Can any one help me with something?

这是西班牙最好的问候

推荐答案

如果您的形式是内部#内容,你应该考虑覆盖您的表单提交事件,如果它不能正常提交和实施你想在JavaScript执行的操作。请参见 http://api.jquery.com/submit/

If your form is inside #content, you should consider overriding your form submit event if it does not submit properly and implementing actions you want performed in javascript. See http://api.jquery.com/submit/

有关动态加载的元素初始化验证,试试这个

For initializing validation on dynamically loaded elements, try this

    var element = "#content form";
    $(element).valid();
    $(element).find("input").each(function () {
        $(this).blur(function () {
            $(this).valid();
        });
    });
    $(element).find("select").each(function () {
        $(this).change(function () {
            $(this).valid();
        });
    });

如果您使用的是不显眼的验证,看的http://xhalent.word$p$pss.com/2011/01/24/applying-unobtrusive-validation-to-dynamic-content/和<一href="http://stackoverflow.com/questions/5468616/validate-dynamically-added-control/6331183#6331183">Validate动态添加的控制

If you are using unobtrusive validation, see http://xhalent.wordpress.com/2011/01/24/applying-unobtrusive-validation-to-dynamic-content/ and Validate dynamically added control

更新:我忘了​​提,您在执行$(document).ready函数是在文档加载执行,因此不执行对AJAX动态加载的内容所有的JavaScript,所以如果你需要附加日期选择器等您加载内容(在$就成功的功能)后,必须做到这一点。

UPDATE: I forgot to mention, all javascript that you execute in $(document).ready function is executed on document load, and therefore is not executed on dynamically ajax loaded content, so if you need to attach datepicker etc, you must do it after loading content (in success function of $.ajax)

这篇关于使用上的JavaScript父文档jQuery的AJAX加载后不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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