2010-07-15 57 views
0

這不符合我的要求。目前,文本字段激活日期選擇器。但我想點擊按鈕來激活日期選擇器:jQuery:如何從與datepicker插入日期的輸入字段分離的元素激活日期選擇器?

<script type="text/javascript"> 
     $j(function() { 
      $j(".prop-expiry input").datepicker({ 
       showTrigger: '#exp-date-button' 
      }); 
     }); 
    </script> 

這個呢,但我希望能夠使用懸停圖像的日期選擇按鈕(目前,它同時顯示了IMG,和懸停IMG ...導致PNG是一個精靈)

<script type="text/javascript"> 
$(function() { 
    $(".prop-expiry input").datepicker({ 
     showOn: 'button', 
     buttonImage: '..images/btn_datepicker.png', 
     buttonImageOnly: true 
    }); 
}); 
</script> 

和我場/按鈕,我想在日期選擇器顯示出來:

<input class="input-field hasDatepicker" 
     id="object_expires_at" 
     name="object[expires_at]" 
     onclick="$j('.prop-expiry input').val(''); 
       $j('.prop-expiry input').css('color', 'black');" 
     size="30" type="text" 
     value="Enter or pick a date"> 
<a id="exp-date-button" class="date-picker">Expiration Date</a> 

我想要什麼:用戶點擊一個#exp-date-button

然後出現日期選擇器。

想法?

回答

1

據我瞭解你的代碼不應該做這樣的事情:

$("#exp-date-button").datepicker({ 
    /* your config */ 
}); 

對於懸停狀態,我建議的CSS解決方案。減少JavaScript總是更好;)和哪個jQuery Datepicker你使用?

+0

css的伎倆。 jquery插入類「ui-datepicker-trigger」的按鈕,所以我可以搞砸了。 – NullVoxPopuli 2010-07-15 21:52:00

相關問題