我的简单 react 代码是:
主要.js:
var ReactDom = require('react-dom');
var Main = React.createClass({
render: function(){
return(
<div>
<a onClick={alert("hello world")} >hello</a>
</div>
)
}
});
控制台出现错误:
TypeError: listener must be a function
错误:
while running this code, I am getting that alert function instead of that this should be on click function.
注意:我正在使用 flux 结构,但给定文件中没有数据填充。
提前致谢
最佳答案
您应该将警报包装在一个函数中,您可以使用粗箭头来完成这项工作
<a onClick={() => alert("hello world")} >hello</a>
关于javascript - React 中的 onClick 函数不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38146517/