刚接触 React js,似乎可以理解为什么 oncopy 事件没有按预期工作。
HTML
<div id="container"></div>
<h1 oncopy="alert('copy1');">
I love react
</h1>
JS
var Hello = React.createClass({
render: function() {
return <div oncopy="alert('copy2');">I hate react</div>;
}
});
ReactDOM.render(
<Hello/>,
document.getElementById('container')
);
最佳答案
使用camel case
传递事件并使用ES6风格的箭头函数执行语句,例如
var Hello = React.createClass({
render: function() {
return <div onCopy={()=> alert('copy2')}>I hate react</div>;
}
});
<强> JSFIDDLE
关于javascript - 为什么 oncopy 不能与 React 一起使用,而是与普通的 JavaScript 代码一起使用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43999624/