这是我用来添加图像和关闭按钮的函数(带有事件侦听器)
function loadframe(img, imgid) {
li = '';
li += '<li><img src="' + img + '" width="100" height="120" /></li>';
//li +='<a href="javascript:void(0)" onclick="removeajax(\''+img+'\','+imgid+')" >Close</a>';
li += '<input type="button" id="activate' + imgid + '" value="close">';
document.getElementById('ulimage2').innerHTML += li;
}
我正在单击一些图像,它们会通过关闭按钮加载到预览窗格中。
我在这里调用这个函数..它包含一个名为
$('#activate' + imgid).click(function() {
//alert(imgid)
var yoda1 = stage.get("#" + imgid);
layery.remove(yodaGroup1);
layery.draw();
});
这是完整的功能..
function initStage1(images, imgid) {
// alert(imgid)
var yodaGroup1 = "yodaGroup1" + imgid;
yodaGroup1 = new Kinetic.Group({
x: 100,
y: 110,
draggable: true,
name: imgid
});
layery.add(yodaGroup1);
stage.add(layery);
var yoda1 = new Kinetic.Image({
image: images.yoda1,
x: 0,
y: 0,
width: 100,
height: 120,
id: imgid,
name: "image",
detectionType: "Pixel"
});
$('#activate' + imgid).click(function() {
//alert(imgid)
var yoda1 = stage.get("#" + imgid);
layery.remove(yodaGroup1);
layery.draw();
});
yodaGroup1.add(yoda1);
yodaGroup1.on("dragstart", function() {
yodaGroup1.moveToTop();
layery.draw();
});
yodaGroup1.on("dblclick dbltap", function() {
layery.remove(yodaGroup1);
layery.draw();
});
yodaGroup1.on("dragend", function() {
layery.draw();
yoda1.saveImageData();
});
addAnchor(yodaGroup1, 0, 0, "topLeft");
addAnchor(yodaGroup1, 100, 0, "topRight");
addAnchor(yodaGroup1, 100, 120, "bottomRight");
addAnchor(yodaGroup1, 0, 120, "bottomLeft");
stage.draw();
yoda1.saveImageData();
}
此 onclick 仅适用于最后上传的图像.. 或者如果我只添加一个图像然后删除它.. 它工作正常.. 如果我添加超过 1 个图像,它仅适用于最后上传的图像的关闭按钮.. 我在这里使用 kineticjs 来实现 HTML5 画布功能