单击文本框和日历按钮时如何设置datepicker?

时间:2013-12-19 05:41:56

标签: jquery

嗨我旁边有两个文本框和两个日历按钮,当你按下日历按钮然后弹出一个日历然后所选日期将进入文本框但现在我的要求是即使按下文本框也是应该会出现calander弹出窗口,以及点击日历按钮时也应该出现。 在这里我的代码是...请cdan任何人帮助我如何修改我的代码,以实现我的要求,因为我说.....

<script>
$(function() {
 $( "#datepicker1" ).datepicker({
dateFormat: "dd/mm/yy" ,
 showOn: "button",
 buttonImage: "images/cal.gif",
 buttonImageOnly: true
 });
 });
$(function() {
$( "#datepicker2" ).datepicker({
    dateFormat: "dd/mm/yy" ,
showOn: "button",
buttonImage: "images/cal.gif",
buttonImageOnly: true
});
});
  </script>
<body>
<tr>
<td>Memo Start Date :</td>
<td><form:input name="dateOfBirth" id="datepicker1" path="memoStartDate" /> 
    </td>
 </tr>
   <tr>
    <td>Memo End Date :</td>
<td><form:input id="datepicker2"  path="memoEndDate" /> </td>
    </tr>           
       <tr>

3 个答案:

答案 0 :(得分:6)

使用showOn: "both"选项进行设置

$(function () {
    $("#datepicker1").datepicker({
        dateFormat: "dd/mm/yy",
        showOn: "button",
        buttonImage: "images/cal.gif",
        buttonImageOnly: true,
        showOn: "both"
    });
});
$(function () {
    $("#datepicker2").datepicker({
        dateFormat: "dd/mm/yy",
        showOn: "button",
        buttonImage: "images/cal.gif",
        buttonImageOnly: true,
        showOn: "both"
    });
});

演示:Fiddle

答案 1 :(得分:0)

你可以做showOn:“按钮”显示On:“both” 点击按钮和文本框打开日历。

 <script>
    $(function () {
      $("#datepicker2").datepicker({
    dateFormat: "dd/mm/yy",
    showOn: "button",
    buttonImage: "images/cal.gif",
    buttonImageOnly: true,
    showOn: "both"
      });
   });
</script>

答案 2 :(得分:0)

<script>    
 $(function()     {
    $( "#datepicker" ).datepicker();    
 });    
 $(function()     {    
    $( "#datepicker1" ).datepicker({    
    changeMonth: true,    
    changeYear: true    
 });           

</script>   
<input  type="text" name="date"  id="datepicker"   />
<input type="text" name="edate"  id="datepicker1"/>