In JavaScript can I make a “click” event fire programmatically for a file input element?

前端 未结 28 1335
囚心锁ツ
囚心锁ツ 2020-11-21 06:29

I\'d like to make a click event fire on an tag programmatically.

Just calling click() doesn\'t seem to do anything or at lea

28条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-11-21 06:59

    I had a tag hidden from view. What I did was attaching the "onClick" event to any visible component of any type such as a label. This was done using either Google Chrome's Developer Tools or Mozilla Firefox's Firebug using the right-click "edit HTML" command. In this event specify the following script or something similar:

    If you have JQuery:

    $('#id_of_component').click();
    

    if not:

    document.getElementById('id_of_component').click();
    

    Thanks.

提交回复
热议问题