2013-03-18 116 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")