2011-05-04 33 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