2014-02-11 83 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'