【发布时间】:2015-11-11 12:59:25
【问题描述】:
我有一个神秘的问题:当我点击按钮或按回车时,什么都没有发生。
Row = ReactBootstrap.Row
Col = ReactBootstrap.Col
Input = ReactBootstrap.Input
Button = ReactBootstrap.Button
@NewSession = React.createClass
handleSubmit: (e) ->
alert 'f'
e.preventDefault()
Dispatcher.query('sessions', {}, 'POST')
render: ->
<form onSubmit={@handleSubmit} noValidate>
<Row>
<Col md={6} mdOffset={3} className='text-center'>
<Input type='text' placeholder='Your username' ref='login' />
<Input type='text' placeholder='Your password' ref='password' />
<Button bsStyle='success'>Sign in</Button>
</Col>
</Row>
</form>
这种奇怪行为的原因是什么?为什么handleSubmit 不起作用?
更新
如果我将onClick={@handleSubmit} 处理程序放在按钮上,点击就可以了
【问题讨论】:
-
你试过在
handleSubmit函数中记录一些东西吗? -
是的,我已经编辑了这个问题。
console.log和 'alert' 都不能给我任何东西 -
试试这个
{this.handleSubmit}而不是{@handleSubmit}。看看有没有帮助。 -
完全相同
-
奇怪。在我看来还可以。
console窗口中是否有任何错误?
标签: javascript coffeescript reactjs