2013-03-06 38 views
0

我上的按鈕綁定鼠標按下這樣的:JQuery->事件繼續

$(".save_btn").bind("mousedown", {PID: ParticipantID}, LicenseCheck); 

在LicenseCheck功能,我驗證某些字段,如果驗證失敗,我 函數調用Event.preventDefault,調用函數來顯示錯誤消息並返回false; 如果驗證成功,則返回true。但事件不會繼續,它幾乎就像停止。

function LicenseCheck(event) { 
    var PID  = event.data.PID; 
    var showError = false; 
    var c   = null; 

    if($.trim($("#lname_"+PID).val()) != "") { 
     if($.trim($("#ln_"+PID).val()) == "") { 
      showError = true; 
      c = $("#ln_"+PID); 
     } 
    } else { 
     if($.trim($("#lname_"+PID).val()) == "") { 
      showError = true; 
      c = $("#lname_"+PID); 
     } 
    } 
    if ($('input[type=radio][name^="lt_'+PID+'"]:checked').length == 0) { 
     showError = true; 
     c = $('input[type=radio][id^="lt_'+PID+'"]')[0]; 
    } 
    if(showError) { 
     ShowFormError(c, PID); 
     event.preventDefault; 
     return false; 
    } else { 
     return true; 
    } 
} 

function ShowFormError(control, PID) { 
    $parent = $("#p_div_"+PID); 
    var pos = control.position(); 
    $arrows = $("<div>", {"class": "formErrorArrow"}) 
     .append($("<div>", {"class": "line10", html: '<!-- -->'})) 
     .append($("<div>", {"class": "line9", html: '<!-- -->'})) 
     .append($("<div>", {"class": "line8", html: '<!-- -->'})) 
     .append($("<div>", {"class": "line7", html: '<!-- -->'})) 
     .append($("<div>", {"class": "line6", html: '<!-- -->'})) 
     .append($("<div>", {"class": "line5", html: '<!-- -->'})) 
     .append($("<div>", {"class": "line4", html: '<!-- -->'})) 
     .append($("<div>", {"class": "line3", html: '<!-- -->'})) 
     .append($("<div>", {"class": "line2", html: '<!-- -->'})) 
     .append($("<div>", {"class": "line1", html: '<!-- -->'})); 

    $item  = $("<div>", {"class": "formError hidden", id: "form_error_"+PID}) 
     .append($("<div>", {"class": "formErrorContent", html: "* This field is required<br>"})) 
     .append($arrows); 
    $parent.append($item); 
    $("#form_error_"+PID).css("top", pos.top-35); 
    $("#form_error_"+PID).css("margin-top", 0); 
    $("#form_error_"+PID).css("opacity", 0.87);  
    $("#form_error_"+PID).css("left", pos.left+control.width()+-30); 
    $("#form_error_"+PID).css("position", "absolute"); 
    $("#form_error_"+PID).removeClass('hidden'); 
    $("#form_error_"+PID).bind('click', function() { 
     $(this).addClass('hidden'); 
    }); 
} 

如何讓它在沒有mousedown處理程序的情況下單擊時應該繼續執行?

+1

您可能希望查看[.on()](http://api.jquery.com/on/)方法,作爲使用jQuery中事件的更新方法。 – 2013-03-06 20:32:38

+1

你想繼續什麼? – Terry 2013-03-06 20:32:43

+0

我想通了,我只需觸發'點擊'。 – MB34 2013-03-06 20:33:15

回答

1
$(this).trigger('click'); 

之前返回真正的工作就像一個魅力。

+2

請使用您問題上的編輯鏈接添加其他信息。後回答按鈕應該只用於問題的完整答案。 – 2013-03-06 20:53:56

+0

因爲我是那個提出了答案的人,所以我不想讓別人進來並添加一個答案,讓我不得不接受它。 – MB34 2013-03-06 23:00:42