从父框架管理iframe的表单? [英] manage iframe's form submit from parent frame?

查看:140
本文介绍了从父框架管理iframe的表单?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从父框架更改iframe中表单的提交功能。以下代码应该这样做,但没有任何问题。并且chrome的调试器中没有显示错误。有什么问题?

I want to change the submit function of form in iframe from the parent frame. The following code should do that, but nothing hapen. And no error shown in chrome's debugger. What is wrong?

<iframe src="test.php" id="frame"></iframe>

<script type="text/javascript">
$("#frame").contents().find("form").submit(function(){
    return true;
});
</script>


推荐答案

确保您正在操纵此iframe的DOM一旦通过将您的呼叫包裹在 .load 回调中来加载其内容:

Make sure that you are manipulating the DOM of this iframe once its contents has been loaded by wrapping your call inside a .load callback:

<iframe src="test.php" id="frame"></iframe>

<script type="text/javascript">
    $('#frame').load(function() {
        $(this).contents().find('form').submit(function() {
            return false;
        });
    });
</script>

这篇关于从父框架管理iframe的表单?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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