javascript/jquery单击函数触发两次

bnl4lu3b  于 2023-02-21  发布在  Java
关注(0)|答案(1)|浏览(97)

最近我把主题从colormag改成generatepress了。
更改主题后,此javascript函数出错,触发两次

我不知道怎么修。

$("#generatebtn").click(function() {
  $("<div>").attr("id", "data").appendTo("body");
  var a = new Array,
    e = $("#arrayA1").val(),
    t = $("#arrayA2").val(),
    l = $("#arrayA3").val(),
    r = $("#arrayA4").val(),
    n = $("#arrayA5").val(),
    y = $("#arrayA6").val(),
    s = $("#arrayA7").val(),
    d = $("#arrayA8").val(),
    c = $("#arrayA9").val(),
    o = $("#arrayA10").val();
  a.push(e), "" != t && a.push(t), "" != l && a.push(l), "" != r && a.push(r), "" != n && a.push(n), "" != y && a.push(y), "" != s && a.push(s), "" != d && a.push(d), "" != c && a.push(c), "" != o && a.push(o);
  var m = new Array,
    u = $("#arrayB1").val(),
    p = $("#arrayB2").val(),
    i = $("#arrayB3").val(),
    k = $("#arrayB4").val(),
    B = $("#arrayB5").val(),
    g = $("#arrayB6").val(),
    v = $("#arrayB7").val(),
    h = $("#arrayB8").val(),
    b = $("#arrayB9").val(),
    A = $("#arrayB10").val();
  m.push(u), "" != p && m.push(p), "" != i && m.push(i), "" != k && m.push(k), "" != B && m.push(B), "" != g && m.push(g), "" != v && m.push(v), "" != h && m.push(h), "" != b && m.push(b), "" != A && m.push(A);
  var E = new Array,
    I = $("#arrayC1").val(),
    C = $("#arrayC2").val(),
    f = $("#arrayC3").val(),
    x = $("#arrayC4").val(),
    L = $("#arrayC5").val(),
    M = $("#arrayC6").val(),
    T = $("#arrayC7").val(),
    H = $("#arrayC8").val(),
    w = $("#arrayC9").val(),
    N = $("#arrayC10").val();
  E.push(I), "" != C && E.push(C), "" != f && E.push(f), "" != x && E.push(x), "" != L && E.push(L), "" != M && E.push(M), "" != T && E.push(T), "" != H && E.push(H), "" != w && E.push(w), "" != N && E.push(N), console.log(m), console.log(E), console.log(a);
  let j = getAllCombinations([a, m, E]);
  for (var q in j)
    for (var z in document.getElementById("data").innerHTML += " ", document.getElementById("data").innerHTML += "&nbsp;", j[q]) document.getElementById("data").innerHTML += j[q][z];
  var D = document.getElementById("data").innerHTML.replace(",", "");
  document.getElementById("data").innerHTML = D
});
var str = document.getElementById("data").innerHTML,
  ress = str.split(" ");
console.log(ress);

我确信javascript函数在上一个主题中工作得很好。

fykwrbwg

fykwrbwg1#

可能另一个脚本正在触发事件。请尝试此操作

$("#generatebtn").click(function(e) {
e.stopPropagation();
e.preventDefault();
// your code

更多信息请访问What's the difference between event.stopPropagation and event.preventDefault?

相关问题