我正在使用Joomla 3.0,我正在打开一个上传照片的模态(子)窗口。在模态窗口中上传照片时,照片的缩略图将添加到父窗口(正在工作)。我一直在努力的是在父级缩略图下添加javascript动作按钮(取消发布,删除..),“onclick”事件将不会附加。我使用简单的javascript,但JQuery& Mootools可用。这是代码,除了onclick之外的所有东西都在工作:
function addPhotoDiv(id, file) {
var grp = window.parent.document.getElementById('tspics');
var innerDiv = document.createElement("div");
innerDiv.className = "smallpreimage";
innerDiv.style.backgroundImage = "url(images/photos/" + file + ".jpg)";
grp.appendChild(innerDiv);
var limg = window.document.createElement("img");
limg.src = "images/tick.png";
limg.className = "actimg";
limg.id = "limg" + id;
limg.alt = "UNPUBLISH";
limg.title = "UNPUBLISH";
limg.onclick = function () {
alert("THIS IS WORKING");
};
innerDiv.appendChild(limg);
}
我知道我添加onclick的方式不是唯一/最佳方式,我也尝试了以下方法:
limg.addEventListener("click", function(){ alert("THIS IS WORKING"); });
// nope
// I thought maybe I needed to create the element first, then attach the event
var dis = window.parent.document.getElementById("limg" + id);
dis.onclick = function() {
alert("THIS IS WORKING");
}