Trigger a click on a different element when clicking an other div

前端 未结 1 1875
迷失自我
迷失自我 2021-01-05 18:13

Right now I have a div that is basically a giant square and inside the div I have another div that is simply text that says \"Upload File\" and a hidden input type = file el

1条回答
  •  庸人自扰
    2021-01-05 18:20

    You can use "refs" to refer to nodes inside a component and trigger things on them.

    
    FileBox = React.createClass({
            _handleClick: function(e) {
                var inputField = this.refs.fileField;
                inputField.click()
            },
            render: function() {
                return 
    +Add Photo 1
    } })

    Read more about refs here: https://facebook.github.io/react/docs/more-about-refs.html

    0 讨论(0)
提交回复
热议问题