【问题标题】:Target iFrame Body Using jQuery (Same Domain)使用 jQuery 定位 iFrame 主体(相同域)
【发布时间】:2013-11-27 05:09:41
【问题描述】:

我正在尝试使用 jQuery 定位 iFrame 的 body,但它不起作用。

代码如下:

HTML

<div class="editor">
  <iframe id="editorf">
    <body>
    </body>
  </iframe>
</div>

JS

$(function() {
   $('#editorf').contents().find('body').css( " background-color", "none" );
});

iFrame 位于同一个域中,但它是由我的 CMS 生成的,因此我无法直接访问它。如何定位 iFrame 的主体并应用 css background-color:none;

【问题讨论】:

  • 您的控制台有错误吗?您可能会在加载内容之前尝试访问它们...
  • @MatthewBlancarte - 没有产生错误。
  • 不确定它是否会有所作为,但您可以尝试删除背景颜色字符串中的多余空间。

标签: javascript jquery css iframe


【解决方案1】:

看起来你的 css 属性字符串中有一个额外的空间。

" background-color", "none"

应该是

"background-color", "none" 

工作演示:http://jsfiddle.net/X8wDX/1/

【讨论】:

    猜你喜欢
    • 2014-12-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-12-05
    • 1970-01-01
    • 2017-10-20
    • 1970-01-01
    相关资源
    最近更新 更多