比较以下案例时,我感到很惊讶:
button = document.getElementById("addSugerenciaButton");
if (button != null) {
button.onclick = "post_to_url('" + addSugerenciaURL + "', idBuzon', '" + id + "');";
}
button = document.getElementById("removeBuzonButton");
if (button != null) {
button.onclick = function() {
if (!confirm(removeSugerenciaMessage)) {
return false;
};
post_to_url(removeBuzonURL, 'idBuzon', id);
};
}
button = document.getElementById("editBuzonButton");
if (button != null) {
button.setAttribute("onclick","post_to_url('" + editBuzonURL + "', 'idBuzon', '" + id + "');");
}
只是后者似乎改变了 HTML(至少使用 Firebug 进行检查),而其余的虽然也可以正常工作,但它们没有在 editBuzonButton 元素中显示任何 onclick 事件。
任何想法为什么会发生这种情况?