2012-03-08 49 views
0

我想在另一個函數validateForm中調用函數notEmpty。但是我需要通過這個函數的選擇器並在提交表單之後。調用函數提交按鈕

請看:

$("#accountemail").blur(notEmpty); 
$("#submit_account").click(validateForm); 

function notEmpty() 
{ 
    if($(this).val() == "") 
    { 
     // Send a warning message 
     warn($(this), "notEmpty"); 
     return false; 
    } 

    else 
    { 
     // Remove a warning message 
     unwarn($(this), "notEmpty"); 
     return true; 
    } 
} 

function validateForm() 
{ 
    // How i can call the function passing the selector and after submit the form? 
} 
+0

什麼是「選擇器」? – 2012-03-08 14:45:33

+0

表單 – KillCloud 2012-03-08 15:06:00

回答

0

加入一個參數傳遞給您的validateForm功能。當你將函數名稱作爲參數傳遞給clcik處理函數時,jQuery將返回函數中的元素

$("#submit_account").click(validateForm); 

function validateForm() 

{ 

    /* $(this) will be the same as $("#submit_account")*/ 
} 
+0

的元素ID不會'element'包含事件對象而不是第一個片段中的元素? – 2012-03-08 15:21:18

+0

oops..asleep at wheel..updated ..謝謝@Kevin B – charlietfl 2012-03-08 15:22:18

+0

你可以更精確嗎?我試過$(「#accountemail」)。notEmpty();但doens't沒有工作 – KillCloud 2012-03-08 16:56:55