OnClick功能无法在iframe上启动? [英] OnClick function doesnt fire on iframe?

查看:81
本文介绍了OnClick功能无法在iframe上启动?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使点击功能在单击iframe时触发,但不会触发.有可能做到吗?

I am trying to make click function fire when iframe is being clicked but It doesn't fire. Is it possible to do it ?

$("#iframe").click(function() {
alert("works");
});

<iframe id="iframe" src="http://site.com" scrolling="no"></iframe>

推荐答案

另一种解决方案是覆盖透明div并向该div添加click事件. 工作示例: http://jsfiddle.net/w1ll3m/AxJHH/

Another solution is to overlay a transparent div and add a click event to that div. Working sample: http://jsfiddle.net/w1ll3m/AxJHH/

<div class="container">
    <iframe src="#url"></iframe>
    <div class="overlay"></div>
</div>

css将div.overlay放置在iframe上:

css to position the div.overlay over the iframe:

.container{position:relative;float:left;}
.overlay{top:0;left:0;width:100%;height:100%;position:absolute;}

添加事件:

$('.overlay').click(function(){alert('hello');});

这篇关于OnClick功能无法在iframe上启动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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