我们如何通过javascript设置图像的替代文本 [英] how we can set alt text of image through javascript
本文介绍了我们如何通过javascript设置图像的替代文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你好
您能告诉我如何通过javascript设置图像的替代文本吗?也请给出示例.
hello
can u tell me How we can set alt text of image through javascript please give example also thanks
推荐答案
尝试一下是否可行,我还没有测试过.
Try if it works, I haven''t tested it.
<script type="text/javascript">
function init(){
imgs = document.images;
for(i=0;i<imgs.length;i++){>
imgs[i].alt="";
}
}
</script>
<body onload="init()"></body>
或
or
<script>
function set_alt_attribute(image) {
image.setAttribute("alt", image.src); ''image.src or whatever
}
</script>
<img src="my_image.jpg" onload="set_alt_attribute(this);">
</img>
OP写道:
请参阅此示例,如果我显示此ex,则将鼠标悬停在图像文本上时,文字应显示为"Angry face"右侧
see this example if i display this ex then on mouseover on image text should display like "Angry face" right
为此,您需要Image的title
属性.看这个.
For that you need to title
property of Image. Look at this.
document.getElementById("ImageID").title="Dynamic title";
这篇关于我们如何通过javascript设置图像的替代文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文