【问题标题】:Prettyphoto and event click on iframePrettyphoto 和事件点击 iframe
【发布时间】:2013-03-04 09:56:56
【问题描述】:

uu我正在尝试检测 iframe 内的点击事件。我已经在 SO 上找到了一些(不工作的)解决方案,但我无法修复它们并让它们在我的代码上工作。

如何在 iframe 内检测点击事件的目标?

由于 PrettyPhoto 只是由

加载
$("a[rel^='prettyPhoto']").prettyPhoto();

我希望有一个类似于

的解决方案
$("a[rel^='prettyPhoto']").prettyPhoto(
     $('#myframe').bind('click', function(event) {
          alert("cliked");
     })
);

但这不起作用。有什么想法吗?

【问题讨论】:

    标签: jquery iframe onclick frame prettyphoto


    【解决方案1】:

    使用.on()

    $('#myframe').on('click', function(event) {
           alert("cliked");
    })
    

    【讨论】:

    • 这不起作用...我已经尝试过live()、on()、bind(),它们都不起作用
    【解决方案2】:

    你可以把它放在prettyphoto();之外,如果你使用最新的jquery,那么使用.on()处理程序:

    $("a[rel^='prettyPhoto']").prettyPhoto();
    $('#myframe').on('click', function(event) {
          alert("cliked");
    });
    

    【讨论】:

    • 我已经尝试过 live()、on()、bind(),它们都不起作用。我也尝试将处理程序放在 PrettyPhoto 初始化之外,但没有改变结果..
    • 最好在您的帖子问题中也发布 html。
    • html 没关系。所需的一切都在我的第一篇文章中。 html 只是 html(当您单击链接时,iframe 显示为 prettyPhoto),我的问题是 jquery 和 iframe .. 我如何从我的主页处理,点击 iframe 中的页面?
    猜你喜欢
    • 1970-01-01
    • 2023-04-09
    • 2023-03-23
    • 1970-01-01
    • 2013-02-11
    • 2020-05-19
    • 2012-11-06
    • 1970-01-01
    相关资源
    最近更新 更多