我正在研究React。以下组件是一个示例。当我在IOS上打开页面时,只有touchend可以触发文件对话框,但不能触发touchstart。但是,onmousedown / onmouseup都可以在桌面浏览器上触发它。 ontouchstart有什么特别之处吗?
class Sub extends React.Component {
componentDidMount() {
this.refs.test.ontouchstart = function(e) {
e.preventDefault()
const fileSelector = document.createElement('input');
fileSelector.setAttribute('type', 'file');
fileSelector.click()
console.log('this file dialog fails to open')
}
this.refs.test.ontouchend = function(e) {
e.preventDefault()
const fileSelector = document.createElement('input');
fileSelector.setAttribute('type', 'file');
fileSelector.click()
console.log('this file dialog opens')
}
this.refs.test.onmousemove = function(e) {
e.preventDefault()
}
this.refs.test.onmouseup = function(e) {
e.preventDefault()
}
this.refs.test.onmouseout = this.refs.test.onmouseup
this.refs.test.ontouchmove = this.refs.test.onmousemove
}
render() {
let canvas_style = { border: '2px solid black' }
return (
<div>
<canvas ref='test' style={canvas_style}/>
</div>
)
}
}