jQuery DatePick填充输入 - 多次点击问题 [英] jQuery DatePick Populating Input - Multiple Clicks Issue

查看:99
本文介绍了jQuery DatePick填充输入 - 多次点击问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,我面临的最新困境:

So, the latest dilemma I am facing:

我使用jQuery DatePick(而不是DatePicker)来选择日期,并填充这些日期的输入字段。问题是输入字段将在每次单击日期时填充。因此,如果我单击23rd,然后再次单击它来选择它,它会自动添加到输入(因此数据库数组)两次。

I am using jQuery DatePick (not DatePicker) to select dates and populate an input field with these dates. The problem is that the input field will get filled every time I click a date. Therefore, if I click the 23rd, then click it again to DEselect it, it automatically gets added to the input (and therefore the database array) twice.

代码如下:

    <script type="text/javascript">
 $(document).ready(
  function (){
  $('.datePick').datepick({ 
      //rangeSelect: true,
   multiSelect: 999, 
   monthsToShow: 2,
   multiSeparator: ':',
   monthsToShow: 3, 
   monthsToStep: 3, 
      prevText: 'Prev months', 
   nextText: 'Next months',
   onSelect: function(date) 
   { 
    var all_dates = $('#dateSelect').val();
          for (var i = 0; i < date.length; i++) 
    { 
              all_dates = ':'+$.datepick.formatDate('yyyy-mm-dd', date[i]);
          } 
          $('#dateSelect').val($('#dateSelect').val()+all_dates);
   }});
  //Ajax call for image uploader
   });
 </script>

然后我有两个元素:

 <div class="datePick"></div>


<input id="dateSelect" name="dateSelect" value=""/>


推荐答案

为了解决这个问题, onSelect 活动如下:

To solve the problem, I changed the code in the onSelect event as follows:

   onSelect: function(date) 
   { 
    var all_dates = '';
          for (var i = 0; i < date.length; i++) 
            { 
              all_dates = all_dates + ':'+$.datepick.formatDate('yyyy-mm-dd', date[i]);
          } 
          $('#dateSelect').val(all_dates);
   }

我希望它有帮助。

这篇关于jQuery DatePick填充输入 - 多次点击问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆