[英]Why isn't oncopy working with React but working with normal JavaScript code?
新的反應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')
);
起初,道具反應使用大寫字母(駱駝案)。 其次,您需要在jsx中將函數作為事件處理程序傳遞。 當您使用""
它被認為是字符串值。 你需要在花括號{}
之間傳遞函數:
onCopy={() => alert('copy2')}
使用camel case
傳遞事件並使用ES6樣式箭頭函數執行語句
var Hello = React.createClass({
render: function() {
return <div onCopy={()=> alert('copy2')}>I hate react</div>;
}
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.