执行 onclick 事件,不点击。

use*_*621 3 javascript photo onclick simulate

我正在使用一个名为 photobooth for JavaScript 的脚本,用户应该在其中单击相机图标来拍照,但我希望它被执行代码。这是我认为是 photobooth 拍照事件的代码片段。

var L = g("blind");
g("trigger").onclick = function () {
    L.className = "blind", L.style.opacity = 1, setTimeout(function () {
        L.className = "blind anim", L.style.opacity = 0
    }, 50);
    var e = {};
    C.isActive() ? e = C.getData() : f ? e = {
        x: (p - T.videoWidth) / 2,
        y: (d - T.videoHeight) / 2,
        width: T.videoWidth,
        height: T.videoHeight
    } : e = {
        x: 0,
        y: 0,
        width: p,
        height: d
    };
    var t = y("canvas");
    t.width = e.width, t.height = e.height;
    if (f) t.getContext("2d").drawImage(T, Math.max(0, e.x - (p - T.videoWidth) / 2), Math.max(e.y - (d - T.videoHeight) / 2), e.width, e.height, 0, 0, e.width, e.height);
    else {
        var n = x.getImageData(e.x, e.y, e.width, e.height);
        t.getContext("2d").putImageData(n, 0, 0)
    }
    h.onImage(t.toDataURL())
};
Run Code Online (Sandbox Code Playgroud)

我想调用该事件或更改它以便我可以调用它,我对 js 不是很好,所以任何帮助都会很棒!

这是来源:photobooth js

Mp *_*ega 6

使用 jquery 是一种选择吗?你可以做这样的事情

$("#trigger").click();
Run Code Online (Sandbox Code Playgroud)

或者如果你真的想要原生 js 你可以做这样的事情

document.getElementById("trigger").click();
Run Code Online (Sandbox Code Playgroud)