【发布时间】:2010-06-16 19:03:53
【问题描述】:
这是我的 JS 代码的重要部分:
function createClose() {
var cButton = document.createElement("img");
cButton.src = "close.gif";
cButton.style.cursor = "pointer";
cButton.onclick = closeWindow;
document.getElementById("my_window").appendChild(cButton);
}
function closeWindow() {
document.getElementById("my_window").style.display = "none";
}
图像被创建并附加,但在单击时没有调用 onClick 事件。我也尝试过使用匿名函数,但也没有用。
不,我不会使用 jQuery(尽管我相信你会更容易)。
【问题讨论】:
-
第 3-5 行中的
img应该是cButton吗? -
JQuery 解决方案好吗?