0
工作,我有input
UL監聽器onchange事件不能在IE
<ul id="list">
<li><input type="text" /></li>
<li><input type="text" /></li>
<li><input type="text" /></li>
<li><input type="text" /></li>
</ul>
原因的名單裏有很多人,我讓ul
做事件委派:
function addHandler(element, type, handler) {
if (element.addEventListener) {
element.addEventListener(type, handler, false);
} else if (element.attachEvent) {
element.attachEvent("on" + type, handler);
} else {
element["on" + type] = handler;
}
}
addHandler(document.getElementById("list"), "change", function(event) {
event = event || window.event;
var target = event.target || event.srcElement;
if (target.nodeName === "INPUT") {
alert(target.value);
}
});
這在Chrome,Firefox中運行良好,但在IE中不行,有什麼問題?
小提琴:http://jsfiddle.net/94ngc/