微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

html – iframe的替代文字

对于HTML中的img标记,我们有替代文本alt属性,当图像没有出现时,它会显示出来.我也尝试将标签与iframe一起使用.
<iframe src="www.abc.com" alt="Web site is not avaialable">

但是当给出src =“”时,替代文本不会出现.只是想知道我是否可以以任何其他方式实现替换文本,如果没有给出src?

解决方法

由于我的第一次尝试误解了你的问题,让我们试试这个:
<script>
$(function () {

    $("iframe").not(":has([src])").each(function () {

    var ifrm = this;

    ifrm = (ifrm.contentwindow) ? ifrm.contentwindow : (ifrm.contentDocument.document) ? ifrm.contentDocument.document : ifrm.contentDocument;

    ifrm.document.open();
    ifrm.document.write($(this).attr("alt"));
    ifrm.document.close();

    });

});
</script>

这将读取任何iframe的“alt”标记值,其中没有src属性或带有空值的src属性,并将alt文本写入该iframe的正文中.

Write elements into a child iframe using Javascript or jQuery开始协助

原文地址:https://www.jb51.cc/html/231524.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐