在iframe的情况下,jQuery html()将失败

jQuery html() fails in case of iframe?

本文关键字:失败 html jQuery iframe 情况下      更新时间:2023-09-26

实际上,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>

这将返回未定义

在这些情况下,我是否缺少一些变通方法?

iframe的

open标签在哪里?
<section>some text with mixed tags and an <iframe /> </section>

更新

当@Mike c(谢谢Mike)纠正我时,问题是你的自闭标签<iframe />

如果编写则有效

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

Fiddle