使用jQuery在iFrame元素上定义一个事件 [英] Define an event on iFrame element with jQuery
问题描述
我尝试在iFrame上的img标签存储上定义一个现场活动。例如,当我点击iFrame上的图像时,我想获得一个简单的javascript警报框。
你知道我如何为iFrame定义事件,因为我想把一个东西像 $('img')。live(click,function()
....但只适用于iFrame上的元素。 / p>
请注意:在加载页面后,我的iFrame中img标签是动态添加的。
Nicolas
你可以做如果你
- 确保iframe中的页面有自己的jQuery加载副本[ed .: 只有真正的必要对于外部文档的框架页面本身内部的jQuery操作
- ,可以像这样工作到iframe文档:
$('#iframeId')。contents()。find('img')// ...
I try to define a live event on img tags store on a iFrame. For example, I would like obtain a simple javascript alert box when I click a image on my iFrame.
Do you know how i can define the events for the iFrame, because I would like to put a thing like $('img').live("click",function()
.... but only for the elements on iFrame.
Please note: img tags are dynamically added on my iFrame after page load.
Thanks for your help.
Nicolas
You can do it if you
- make sure that the page in the iframe has its own copy of jQuery loaded [ed.: only really necessary for jQuery operations internal to the frame's page itself]
- from the outer document, work into the iframe document like this:
$('#iframeId').contents().find('img') // ...
这篇关于使用jQuery在iFrame元素上定义一个事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!