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开始协助

相关文章

vue阻止冒泡事件 阻止点击事件的执行 &lt;div @click=&a...
尝试过使用网友说的API接口获取 找到的都是失效了 暂时就使用...
后台我拿的数据是这样的格式: [ {id:1 , parentId: 0, name:...
JAVA下载文件防重复点击,防止多次下载请求,Cookie方式快速简...
Mip是什么意思以及作用有哪些