2012-07-31 127 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()是否应该在日期的实际点击事件上发布日期,而不必将其绑定到表单提交。

相关问题