开发者

jquery datepicker onclick help

I'm developing with php and trying to work jquery's datepicker into my app. I'm trying to display a datepicker that's tied to a particular input field. I have the following code. The problem is that the first time i click on the input, nothing happens. Only when I unfocus and then reclick on it will it display the picker. How do i get it to display the datepicker on the first click?

<script>
function open_picker(X)
    {
        $( X ).datepicker({
            autoSize: true,
            showOtherMonths: true开发者_如何学编程,
            selectOtherMonths: true });       
    };
</script>
<?php $datepickerid = "datepicker" ?>
<input id='<?php echo $datepickerid; ?>' onClick='open_picker("<?php echo "#".$datepickerid; ?>");' type='text' value='05/21/2011' size='10'>

I need to pass the input ID's through a function because i will be using a php loop to produce the datepicker inputs with different ID's.

Thanks in advance!


Assuming you are using JQuery UI Datepicker your function open_picker() is not opening a date picker. What that code does is binding a date picker to the input passed as parameter X. That's why on first click nothing happens: because the date picker is created on first click. What you need to do to create multiple datepickers by php is something like:

<script type="text/javascript">
   <?php
   $datepickers_ids = array("#all", "#the", "#datepickers", ".selectors");
   for($i = 0; $i < count($datepickers_ids); $i++) { ?>
      $("<?php print $datepickers_id[$i]; ?>").datepicker();
   <?php } ?>
</script>

This is going to generate a datepicker for each selector in $datepickers_ids

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜