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

前端 未结 1 1859
迷失自我
迷失自我 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 <div id="test" onClick={this._handleClick}>
                           <input ref="fileField" type="file" name="image1" accept=".jpg,.jpeg,.png" id="img1" />
                           <div id="uploadPhotoButtonText">
                               +Add Photo 1
                           </div>
                       </div>
            }
        })
    
    
    

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

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