2012-07-31 119 views
0

Ajax調用我寫的代碼,日期選擇器之前:datepicker打開後,第二次點擊ajax調用?如何在第一次點擊時打開它?

<script type="text/javascript"> 
    $(function() { 
     $("#birthdate").focus(function() { 
      $(this).datepicker().datepicker("show") 
     }); 
    }); 
    $(function() { 
     $("#joindate").focus(function() { 
      $(this).datepicker().datepicker("show") 
     }); 
    }); 
    </script>   

此功能onfocus事件後調用:

<tr> 
       <td align="left"> 
       <input type="text" id="birthdate" name="birthdate" onfocus="$('#birthdate').datepicker({changeMonth: true,changeYear: true,dateFormat: 'dd/mm/yy',defaultDate: '-20y -1m -247d',yearRange: '-50:+0'});" tabindex="14" style="width:300px; " value="<? if($get_emp!='0')echo $employee_birth; ?>" /><span style="color:#F00;">*</span></td>          

    <td> 
     <input type="text" name="joindate" id="joindate" onfocus="$('#joindate').datepicker({changeMonth: true,changeYear: true,dateFormat: 'dd/mm/yy',defaultDate: '-3y -1m -247d',yearRange: '-50:+0'});" tabindex="15" style="width:300px; " value="<? if($get_emp!='0')echo $employee_join; ?>"/><span style="color:#F00;">*</span> 
     </td> 
    </tr> 

Ajax調用後我調用相同的代碼,但它不是第一次點擊打開,但它打開第二次點擊? 請幫我解決這個問題..........................

回答

0

使用此javascript。你只需要初始化datepicker()一次

$(function() { 
    $('#birthdate').datepicker({changeMonth: true,changeYear: true,dateFormat: 'dd/mm/yy',defaultDate: '-20y -1m -247d',yearRange: '-50:+0'}); 
    $("#joindate").datepicker({changeMonth: true,changeYear: true,dateFormat: 'dd/mm/yy',defaultDate: '-3y -1m -247d',yearRange: '-50:+0'}); 
    $("#birthdate, #joindate").focus(function() { 
     $(this).datepicker("show") 
    }); 
}); 

我刪除了從輸入標籤的焦點屬性:

<input type="text" id="birthdate" name="birthdate" tabindex="14" style="width:300px; " value="<? if($get_emp!='0')echo $employee_birth; ?>" /><span style="color:#F00;">*</span></td>          

<input type="text" name="joindate" id="joindate" " tabindex="15" style="width:300px; " value="<? if($get_emp!='0')echo $employee_join; ?>"/><span style="color:#F00;">*</span> 
0

嘗試這樣的事情,而不是:

$(document).ready(function(){ 
    $("#joindate").datepicker({ 
     // Options and methods here 
    }); 
    $("#joindate").focus(function(){ 
      $("#joindate").datepicker("show"); 
    }); 
    $("#joindate").focus(); 
}); 

你也可以做一個在onSelect事件中,$ .post()是否應該在日期的實際點擊事件上發佈日期,而不必將其綁定到表單提交。

相關問題