jQuery DatePick 填充输入 - 多次点击问题
所以,我面临的最新困境是:
我使用 jQuery DatePick (不是 DatePicker)来选择日期并用这些日期填充输入字段。问题是每次我单击日期时输入字段都会被填充。因此,如果我单击第 23 个,然后再次单击它以取消选择它,它会自动添加到输入(以及数据库数组)两次。
代码如下:
<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=""/>
So, the latest dilemma I am facing:
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.
Code below:
<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>
And then I have both elements:
<div class="datePick"></div>
<input id="dateSelect" name="dateSelect" value=""/>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
为了解决这个问题,我将onSelect事件中的代码更改如下:
希望有帮助。
To solve the problem, I changed the code in the onSelect event as follows:
I hope it helps.