2011-05-04 67 views
1

得到這兩個圖像按鈕:取消類不submitHandler工作忽略按鈕點擊

<input type="image" src="images/Update.png" name="btnSubmit" value="Update"/> 
<input type="image" src="images/Cancel.png" value="Cancel" name="btnCancel" class="cancel" onclick="hide_edit_div()" /> 

現在,即使在取消按鈕點擊運行submithandler。我如何修改它以忽略它?

$(document).ready(function(){ 
    if(this.forms[4]) { 
    $("#editTaskInfo").validate({ 
     rules:{"task_title": {required: true}, 
       "task_instr": {required: true}, 
       "task_desc" : {required: true} 
       }, 
     submitHandler: function(form) { 
     var postData = $('#editTaskInfo').serialize(); 
     $.ajax({type: "POST", 
       url: "post_task.php", 
       data: postData, 
       dataType: "json", 
       success: function(data) { 
        if(textStatus == 'success') { 
        $("div.error span").html(data.msg); 
        $("div.error img").hide(); 
        $("div.error").show(); 
        $("#static_task_price").text(data.price); 
        $("#static_title").text(data.title); 
        $('html, body').animate({scrollTop:0}, 'fast'); 
        hide_edit_div(); 
        $("div.error").fadeOut(10000); 
        } 
       }, 
       error: function(jqXHR, textStatus, errorThrown) { 
        $("div.error span").html(errorThrown); 
        $("div.error img").show(); 
        $("div.error").show(); 
       } 
     }); 
     } 
    } 
    ); 
    } 
}); 

編輯:(因爲我不能回答我自己的8個小時,多麼愚蠢的限制

修改的第二個按鈕是這樣一個div:

<div id="btnCancel" style="float:right; cursor:pointer; width:50px; height:20px; background-image: url(images/Cancel.png); " onclick="hide_edit_div()">&nbsp;</div> 

現在,如果我只能得到它正確定位。 ;-)

回答

1

廣東話您使用簡單:

<img src="images/Cancel.png" id="btnCancel" onclick="hide_edit_div()" /> 
+0

不,仍然進入submitHandler。 – MB34 2011-05-04 17:39:49

+0

@ MB34看到我的答案,爲什麼會發生這種情況並提出修復建議。 – 2011-05-04 18:14:56

+0

@ MB34看到我改變<輸入爲 ariel 2011-05-04 19:22:38

-1

改變這樣的取消按鈕的類型;

<input class="cancel" type="button" id="close" value="Cancel" /> 
+0

問題的作者想要使用「圖像」類型而不是「按鈕」類型,所以這不是答案。 – carbontax 2012-10-20 17:00:54