将事件绑定到iframe的内容并从iframe触发它 [英] bind event to iframe's content and trigger it from iframe

查看:326
本文介绍了将事件绑定到iframe的内容并从iframe触发它的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从目前的项目中分离出非常奇怪的错误:

I have isolated very strange bug from our current project:

index.html (演示)和 iframe.html

do:

1)点击第一个输入并选择任何日期

1) click at the first input and select any date

你会看到 - datepicker改变了iframe!

2)点击第二个输入,写一些符号在页面上的任何可用空间按

2) click at the second input, write some symbols and press at any free space at the page

,您将看到 - 在iframe内更改usual_input。 +usual_input改变了iframe!

内部iframe:

<input id="datepicker" /> <input id="usual_input" />

在index.html绑定到此输入的更改事件:

binded at index.html to the change event at this inputs:

$(this).contents().find("#datepicker").change(... (1)
$(this).contents().find("#usual_input").change(... (2)

在iframe.html到这个输入的更改事件:

binded at iframe.html to the change event at this inputs:

$("#datepicker").change(... (3)
$("#usual_input").change(... (4)

但是№1不能在任何浏览器中运行

But №1 dont work in any browser!

jquery ui的datepicker 触发更改事件100%正确我们不能绑定外部一个iframe?

jquery ui's datepicker trigger change event 100% correctly. why we cant bind to it outside an iframe?

推荐答案

您可以访问iframe的窗口元素通过:

You can access the window element of the iframe by:

$(this)[0].contentWindow.$("#datepicker")

或者这个可能也可以:

this.contentWindow.$("#datepicker");

我希望有帮助。

这篇关于将事件绑定到iframe的内容并从iframe触发它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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