使用jQuery在iFrame元素上定义一个事件 [英] Define an event on iFrame element with jQuery

查看:87
本文介绍了使用jQuery在iFrame元素上定义一个事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试在iFrame上的img标签存储上定义一个现场活动。例如,当我点击iFrame上的图像时,我想获得一个简单的javascript警报框。



你知道我如何为iFrame定义事件,因为我想把一个东西像 $('img')。live(click,function() ....但只适用于iFrame上的元素。 / p>

请注意:在加载页面后,我的iFrame中img标签是动态添加的。





Nicolas

解决方案

你可以做如果你


  1. 确保iframe中的页面有自己的jQuery加载副本[ed .: 只有真正的必要对于外部文档的框架页面本身内部的jQuery操作

  2. ,可以像这样工作到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

  1. 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]
  2. from the outer document, work into the iframe document like this:

$('#iframeId').contents().find('img') // ...

这篇关于使用jQuery在iFrame元素上定义一个事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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