search

Home  >  Q&A  >  body text

javascript - What is the difference between directly clicking a button to trigger an event and calling click to trigger an event through JS?

巴扎黑巴扎黑2756 days ago959

reply all(4)I'll reply

  • 欧阳克

    欧阳克2017-06-28 09:29:32

    The

    click of the element should have the same effect as the manual click.

    First of all b.className is not b.class

    Although I have never used this Clipboard library, literally it is to obtain the .copybutton class through the selector, so you should not be able to obtain it without mounting b on the dom tree. You can try adding document.body.appendChild(b) in front.

    Finally, I suggest you ask questions in the same way as the comments above. Post more code and less pictures, which is inconvenient to read.

    reply
    0
  • 某草草

    某草草2017-06-28 09:29:32

    Um, .click()That’s the abbreviation of jQ, natively you have to call dispatchEvent()


    Reference

    reply
    0
  • 三叔

    三叔2017-06-28 09:29:32

    Problem: Native objects and jq objects are mixed up
    Change the first line to:
    var $b = $('<input type="button" />') Try it

    reply
    0
  • 给我你的怀抱

    给我你的怀抱2017-06-28 09:29:32

    You can bind its click event through the body

    reply
    0
  • Cancelreply