這回的小case如題,額外還有一個,當點擊圖片時響應事件。代碼如下:
複製代碼代碼如下:
<script type="text/javascript">
function onloadEvent(){
var _td = document.getElementById("a1");
var _img = document.createElement("img");
_img.setAttribute("id", "floatImage");
_img.setAttribute("src", "icon.png");
_img.setAttribute("onclick", "clickImage()");
_img.onclick = function(){ //點擊時響應事件
alert("點擊");
//window.location = "http://baidu.com"; 跳轉url
};
_td.appendChild(_img);
}
</script>
在body中的onload事件調用上面這個函數就可以了。