我怎样才能使这个函数对onclick方法作出反应

How can I get this function to react to the onclick method?

本文关键字:方法 onclick 函数      更新时间:2023-09-26

这就是按钮,它目前将获取画布图像并将该图像显示在另一个画布上。

  var formElement2 = document.getElementById("recImage");
     formElement2.addEventListener('click', recImagePressed, false);
     function recImagePressed(e){
         var outputCanvas = document.getElementById("outputCanvas");
         var recr =  canvas2.toDataURL(); 
         outputCtx = outputCanvas.getContext('2d');
         outputCtx.drawImage(canvas2, 0, 0);
         //context2.clearRect(0, 0, canvas2.width, canvas2.height);<----***
     }  
 //***I need the image to clear when the user clicks, the above is wrong

我需要对onclick作出反应的函数是:(如果我手动将png放入函数中,此函数已经过测试并有效)

function init () {  <---------this will be done away with and replaced w/ 
                              onClick ?? <-----------------****
canvas = document.getElementById('canVas');  
ctx = canvas.getContext('2d'); 
draw ();
}
function draw() {   <------This is the function that I need to react to mouse event
img = new Image();  
img.src = myPng.png ***---->This is where I need the canvas image<---------------*** 
fr1 = makeFrame(ctx, makeVect(400,0), makeVect(400, 0), makeVect(0, 400));
img.onload = function(){ 
    ctx.save(); 
    newPainter = cornerSplit(imagePainter,5);
    newPainter(fr1);     
    ctx.restore();
    ctx.save();
    newPainter(flipHorizLeft(fr1));
    ctx.restore();
    ctx.save();
    newPainter(flipVertDown(fr1));  
    ctx.restore();
    ctx.save();
    newPainter(flipVertDown(flipHorizLeft(fr1)));   
       }  
} 
formElement2.onclick = function(args, ...) {
}