2011-11-24 43 views
3

對於HTML中的img標記,我們有替代文本alt屬性,該標記將在圖像未出現時顯示。我也嘗試使用iframe的標籤。iframe的替代文本

<iframe src="www.abc.com" alt="Web site is not avaialable"> 

但是,當給出src=""時,替代文字不會出現。只是想知道,如果我沒有給出src,我是否可以用其他方式實現替代文本?

回答

2

自從我第一次嘗試誤解了你的問題,讓我們試試這個:

<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> 

這將無論是讀了「ALT」標記值的Iframe沒有src屬性或具有空值的src屬性,並將alt文本寫入該iframe的正文中。

Write elements into a child iframe using Javascript or jQuery

+0

- 我已經開始根據這個代碼此琴:http://jsfiddle.net/gnvE9/1/ –

+0

我測試的是: IFRAME