2014-02-11 82 views
0

我有以下的jQuery代码来检测提交事件,并引发其他一些JavaScript代码:jQuery的上提交功能不工作的形式(与HAML)

$('form#send-message').on('submit', function(){ 
     console.log('test'); 
     $('body').modalmanager('loading'); 
    }); 

然而,这并不工作了:

.modal-header 
    Contact info 
    %button.close{ :type => 'button', 'data-dismiss' => 'modal', 'aria-hidden' => 'true' } 
    × 
.modal-body 
    = raw @booth.contact_info 
    %hr 
    = simple_form_for(@booth, url: booth_send_message_path, method: :post, html: { id: "send-message" }, remote: true) do |f| 
    .form-group 
     %textarea#message.form-control{name: "user[message]", placeholder: "Type your message here..."} 
    %input{type: "hidden", name: "user[id]", value: "#{current_user.id}"} 
    .form-actions 
     %button.btn.btn-warning{:type => 'submit'} Send 
     = f.error_notification 

形式的ID绝对匹配,但似乎没有被触发

有为什么事件是不工作的理由?

回答

0
input type=submit and button type=submit 

是不同的东西。在HAML文件,所以只是改变按键输入或绑定回调按钮单击事件

%input.btn.btn-warning{:type => 'submit'} Send 
+0

我改变它,但它仍然没有工作 –

+0

%button.btn.js_submit_form.btn-警告{:type =>'submit'}发送, $(“。js_submit_form”)。(“click”,function(){//逻辑 return false;}); –

0

试试这个:

.form-actions 
    = f.button :submit, 'Send', class: 'button btn btn-warning'