简体   繁体   English

如何使用jquery / javascript在iframe中的div上获取onclick事件?

[英]how to get onclick event on the div inside the iframe using jquery/javascript?

HTML Structure HTML结构

<iframe src="#" scrolling="no" id="gallery-frame">
<div class="gv_filmstrip">
<div class="gv_frame">
<div class="gv_thumbnail current">
<img src="images/grandstand-padang-right/1.jpg">
</div></div>
<div class="gv_frame">
<div class="gv_thumbnail">
<img src="images/grandstand-padang-right/2.jpg">
</div></div>
<div class="gv_frame">
<div class="gv_thumbnail">
<img src="images/grandstand-padang-right/3.jpg">
</div></div>
</div>
<div class="gv_panel"><img src="images/grandstand-padang-right/1.jpg"></div>
<div class="gv_panel"><img src="images/grandstand-padang-right/2.jpg"></div>
<div class="gv_panel"><img src="images/grandstand-padang-right/3.jpg"></div>
</iframe>

What i want is? 我想要的是什么? I want to access the class gv_frame and put a onclick event on it .. in onclick event i need to find the width and height of img in gv_panel 我想访问类gv_frame并在其上放置一个onclick事件..在onclick事件中,我需要在gv_panel找到img的宽度和高度

Scripts i tried.. 我尝试过的脚本

$("#gallery-frame").contents().find("gv_frame").click(function(){
alert("aaa"); // I am not getting the alert
});

2nd try 第二次尝试

var width = $(".gv_panel img").width();
    var height = $(".gv_panel img").height();
    alert("width:"+width+" and height :"+height); // alert is null here

You have typos. 你有错别字。 Remove the contents() and add a . 删除contents()并添加一个. to your class selector. 到您的班级选择器。

$("#gallery-frame").find(".gv_frame").click(function(){
    alert("aaa"); // I am not getting the alert
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM