2014-03-19 58 views
0

我趕上我的形式提交與:表單提交,限制提交按鈕只

$('#my-form').submit(function(e){ 
//do stuff 

這裏是我的html

<div class="row"> 
     <div class="columns"> 
      <button type="submit" class="small right">Save</button> 
     </div> 
</div> 
在我的形式

也是其他按鈕刪除圖片:

<button class="tiny btn-caption" data-reveal-id="caption-modal"> 
    <i class="fa fa-bars fa-2x"></i> 
</button> 

問題是,這些圖像按鈕提交表單,我該如何阻止?

+0

指定'type',否則行爲取決於實現。參考:http://www.w3schools.com/tags/att_button_type.asp – blgt

回答

0

默認<button>將作爲提交按鈕行動刪除。

嘗試,

$("#my-form button[type!='submit']").click(function(e){ 
    e.preventDefault(); 
}); 
+0

@ hsz感謝您編輯TYPO .. –

0

您可以添加remove類按鈕,刪除圖像,並阻止其行動:

<button class="remove tiny btn-caption" data-reveal-id="caption-modal"> 
    <i class="fa fa-bars fa-2x"></i> 
</button> 

JS:

$('#my-form .remove').click(function(){ 
    // post another form or call ajax method 
    return false; 
}); 
-2

使用HTML輸入提交

<input type="submit" value="Submit"> 
+0

謝謝您的回答,但這並不回答發佈的問題。他們想要停止提交按鈕。 – Deanna

1

試試這個

按鈕像<button>Click to do something</button>是提交按鈕。

添加type="button"它將限制表單提交

<button type="button" class="tiny btn-caption" data-reveal-id="caption-modal"> 
    <i class="fa fa-bars fa-2x"></i> 
</button> 
0

需要事件處理程序應用到按鈕本身不是整個形式

$('#my_form button').click(function(){ 
//or 
$('.tiny btn-caption, .small').click(function(){ 

$.post(url,dataString,function(response){ 
    //handle resposne 
    }); 

return false; 
});