html – iframe的替代文字

前端之家收集整理的这篇文章主要介绍了html – iframe的替代文字前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
对于HTML中的img标记,我们有替代文本alt属性,当图像没有出现时,它会显示出来.我也尝试将标签与iframe一起使用.
  1. <iframe src="www.abc.com" alt="Web site is not avaialable">

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

解决方法

由于我的第一次尝试误解了你的问题,让我们试试这个:
  1. <script>
  2. $(function () {
  3.  
  4. $("iframe").not(":has([src])").each(function () {
  5.  
  6. var ifrm = this;
  7.  
  8. ifrm = (ifrm.contentWindow) ? ifrm.contentWindow : (ifrm.contentDocument.document) ? ifrm.contentDocument.document : ifrm.contentDocument;
  9.  
  10. ifrm.document.open();
  11. ifrm.document.write($(this).attr("alt"));
  12. ifrm.document.close();
  13.  
  14. });
  15.  
  16. });
  17. </script>

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

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

猜你在找的HTML相关文章