【问题标题】:jQuery html() fails in case of iframe?jQuery html() 在 iframe 的情况下失败?
【发布时间】:2016-09-07 08:27:35
【问题描述】:

实际上使用 jQuery(v1 和 v2 - 最新版本)面临一个非常奇怪的行为。 我有一个管理内容的脚本,但是当内容包含 iframe 时它会失败。

<article>
   <section>some text with mixed tags and an <iframe /> </section>
</article>

<script>
$('section').each(function() {
   console.log( $(this).html() )
});
</script>

这是返回未定义

我是否缺少在这些情况下使用的一些解决方法?

【问题讨论】:

标签: javascript jquery iframe


【解决方案1】:

你的 iframe 的 open 标签在哪里?

<section>some text with mixed tags and an <iframe /> </section>

更新

@Mike c(感谢 Mike)纠正了我的问题,问题在于您的自我结束标签 &lt;iframe /&gt;

【讨论】:

  • 为什么投反对票?这就是问题的原因...如果您能解释问题所在,我将非常高兴。
  • 没有投反对票,但可能是因为&lt;iframe /&gt; 不是结束标签;它是一个自闭合标签。结束标签是&lt;/iframe&gt;
  • 感谢您的回答,非常感谢。
  • jsfiddle.net/kr7v77pf/3 是自动关闭的示例,而不是 iframe 标签,但没有投票:)
  • 首先,感谢 Scion。然后我做了一点小事,在维护属性的同时替换自动关闭的 iframe:jsfiddle.net/fnc575b3/14
【解决方案2】:

写出来就可以了

<article>
<section>some text with mixed tags and an <iframe></iframe> </section>
</article>

Fiddle

【讨论】:

    猜你喜欢
    • 2014-06-07
    • 2014-01-02
    • 2016-01-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多