这是我用来添加图像和关闭按钮(带有事件监听器)的功能
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画布功能
答案 0 :(得分:0)
尝试将你的yoda变量放在函数之外,因为当你删除你的图层变量时,你也会删除yoda变量及其事件。
答案 1 :(得分:0)
也许它必须对dom娱乐做点什么,尝试更改click()
的{{1}}功能:
on()