<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><title></title><script type="text/javascript">window.onload = function() {for (var i = 0; i < 5; i++) {var obj = document.createElement("div");obj.innerHTML = "div" + i;if (window.attachEvent) {obj.attachEvent("onclick", function() {alert(obj.innerHTML) });//在这里无论点击哪个div,都弹出div4,但如果我想点击div1,就弹出div1,该怎么写啊?}else {obj.addEventListener("click", function() { alert(obj.innerHTML) }, false);}document.body.appendChild(obj);}}</script></head><body></body></html>
2 回答
- 2 回答
- 0 关注
- 672 浏览
添加回答
举报
0/150
提交
取消