React onClick not firing
React onClick not firing
下面的代码不起作用。onClick
事件从未触发,但我在browserify或console中没有看到错误。
var React = require('react');
var Button = React.createClass({
render: function() {
return (
<div className="Button">
<span className="left" onclick={function() {alert("left")}}>Left</span>
<span className="right" onclick={function() {alert("right")}}>Right</span>
<span className="middle" onclick={function() {alert("middle")}}>Middle</span>
</div>
);
}
});
module.exports=Button;
我使用alert只是为了测试小的CSS。为什么onclick不开火?
您的示例中有一个错别字。使用'onClick'代替'onClick'。
<span className="left" onClick={function() {alert("left")}}>Left</span>
参见jsfiddle的工作示例- https://jsfiddle.net/Ltdc8qpr/1/
这里使用箭头函数语法,使用onClick处理程序触发事件。
<span className="left" onClick={() => {alert("left")}}>Left</span>
我也面临着同样的问题。问题是,<span>
标签在左上角,警报只会在我点击左上角时触发。没有其他空格
我把<span>
改为<div>
,它工作了。
相关文章:
- WebSocket onmessage not firing
- Backbone model.change() not firing
- codemirror onKeyEvent not firing
- Dojo onBeforeTransitionIn not firing
- CSS TransitionEnd not firing
- RegisterClientScriptBlock - not firing
- GWT History.back() is not firing onValueChangeHandler
- Signalr connection.start.done not firing
- Javascript XMLHttpRequest onreadystatechanged not firing?
- jstree select_node.jstree not firing
- Jquery not firing
- jQuery.on("drop") not firing
- Javascript window.onload not firing
- MVC 5 javascript not firing
- Javascript FileReader onload not firing
- setTimeout not firing jQuery
- setInterval() not firing
- $.getJSON not firing console.log
- Sails.js IO.socket not firing
- react componentDidMount not firing