Anu*_*lan 6 html iframe jsp alt
alt对于imgHTML中的标记,我们有替代文本属性,该图像将在图像未显示时显示.我也尝试过使用标签iframe.
<iframe src="www.abc.com" alt="Web site is not avaialable">
Run Code Online (Sandbox Code Playgroud)
但是当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>
Run Code Online (Sandbox Code Playgroud)
这将读取任何没有 src 属性或 src 属性为空值的 iframe 的“alt”标记值,并将 alt 文本写入该 iframe 的正文中。
协助使用 Javascript 或 jQuery 将元素写入子 iframe