jQuery - 尝试从iFrame中选择元素(指向并单击) [英] jQuery - Trying to select element from iFrame (point and click)

查看:84
本文介绍了jQuery - 尝试从iFrame中选择元素(指向并单击)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从HTML标记中获取id和元素名称。此代码有效:

I'm trying to get the id and element name from the HTML tags. This code works:

jQuery(document).ready(function(){
   $("*", document.body).mousemove(function(e){
      $('#mpos').html(e.pageX +', '+ e.pageY);
      e.stopPropagation();
      var domEl = $(this).get(0);

      $('#elem').html(domEl.tagName);
      $('#ide').html(domEl.id);
    });
 });

但我希望它也可以在iFrame中使用。如果我现在尝试,它只显示iFrame的id和元素名称。

But I want it to work also inside an iFrame. If I try now, it only displays the the id and the element name of the iFrame.

提前致谢!

推荐答案

这是因为该页面仅将iframe视为单个元素。如果要在iframe中选择单个元素,则需要在iframe内的页面上复制脚本。但是你无法将它传递给父页面AFAIK。

It's because the page only sees the iframe as a single element. If you want to select individual elements in the iframe you'll need to replicate the script on the page inside the iframe. But you won't be able to pass this up to the parent page AFAIK.

如果你可以控制iframe及其内容那么你最好放弃内容直接进入父文档并使用CSS规则 overflow:scroll

If you have control over the iframe and its content then you'd be better off putting the content directly into the parent document and using the CSS rule overflow: scroll.

这篇关于jQuery - 尝试从iFrame中选择元素(指向并单击)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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