How to trigger INPUT FILE event REACTJS by another DOM

后端 未结 6 964
-上瘾入骨i
-上瘾入骨i 2021-01-02 01:53

I have a INPUT BUTTON and INPUT FILE, I want to click the BUTTON and it will trigger the INPUT FILE event

6条回答
  •  被撕碎了的回忆
    2021-01-02 02:36

    EDIT: This is a question I answered a long time ago not knowing very much react at this time. The fun thing is that it has been considered valid ^^.

    So for anyone reading this answer; this answer is wrong and is a very good example of something you shouldn't do in react.

    Please find below a nice anti-pattern, again, don't do it.

    =================================================

    You can achieve this using jQuery:

    this.doClick: function() {
        $('input[type=file]').trigger('click');
    }
    

    React does not provide specific functions to trigger events, you can use jQuery or simply native Javascript: see Creating and triggering events on MDN

提交回复
热议问题