2013-03-18 148 views
1

我想知道如何alt属性中的JavaScript添加到图像,下面是我的代码...提前添加alt属性图像中的JavaScript

var image = document.createElement('img'); 
image.src='../../KY/images/common/buttons/browseIcon.png'; 

感谢。

回答

8

有两种方式:您可以使用alt财产

image.alt = "Your text here" 

setAttribute方法

image.setAttribute("alt","Your text here"); 
-1

你可以只使用alt property。当u创建按钮或DOM JavaScript的任何其他元素

0

上述方法是行不通的,为此使用下面提到的方法

control.setAttribute("title","your tooltip value")