javascript
  • jquery
  • image
  • html5-canvas
  • onclicklistener
  • 2012-08-17 110 views 1 likes 
    1

    这是我使用添加图像和关闭按钮(与事件侦听器)jQuery的onclick事件功能不能正常工作第二次

    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函数工作在过去的uploded图像仅.. 或者如果我只添加一个图像,然后删除it..It工作正常.. 如果我添加更多然后1图像它只适用于最后一次上升图像的关闭按钮.. 我在这里使用kineticjs来实现HTML5画布功能

    +0

    你试图使用'在()的''而不是点击()'?也许你在元素存在之前就绑定了事件。 – jbabey 2012-08-17 15:12:08

    +0

    您是否将整个脚本包装在'$(document).ready(function(){'? – 2012-08-17 15:29:31

    +0

    )中仍然不能正常工作。可能是因为我创建了一个动态关闭函数,事件操作会附加到最后上传的..pic /关闭按钮?不确定 – ashishashen 2012-08-21 11:54:31

    回答

    0

    试着把你的yoda变量放在函数之外,因为当你删除你的图层变量时,你是还会除去yoda变量以及它的事件。

    +0

    onclick无法进入函数本身..我不认为它与函数内的变量有关 – ashishashen 2012-08-21 08:12:30

    0

    也许它做一些带有DOM娱乐,试着改变你的click()功能on()

    $('body').on('click','#activate' + imgid,function() { 
        //alert(imgid) 
        var yoda1 = stage.get("#" + imgid); 
        layery.remove(yodaGroup1); 
        layery.draw(); 
    }); 
    
    相关问题