只有在輸入字段的文本不符合一組條件時,我才需要啓動.datepicker。但是,我不知道如何啓動.datepicker,而不是直接從獲取焦點或正在按下按鈕的字段中啓動。從另一個JS函數啓動jQuery .datepicker
我試圖做...
的HTML
<input type="text" id="userDate" name="userDate" style="width: 100px;" onblur="checkDate(this.id);" />
的JS
function checkDate(theId)
{
var enteredValue = document.getElementById(theId).value;
var checkedValue = evaluateValue(enteredValue); // this checks to see if the text meets the criteria
if (checkedValue == null)
{
// this is where I want to call the .datepicker to have the calendar show up
$("#userDate").datepicker();
}
else
{
document.getElementById(theId).value = checkedValue;
}
}
我知道,這將是更容易,如果日曆剛上來的時候文本字段變得焦點。但是,這不是客戶希望它工作的方式。只要符合所需的格式,他們就會接受用戶輸入。如果沒有,那麼他們想要日曆和默認的強制格式。
謝謝。
我建議在jquery中綁定onblur事件。而不是在HTML中。 – albertjan