在 jQuery 插件中为每个日期添加链接:datepick
我想在日历中的每个日期添加链接。例如,如果我点击 2010 年 8 月 25 日,我希望页面重定向到: xxxxxx/25082010/
(ddmmyyyy)
插件是这样的: http://keith-wood.name/datepick.html
我可以在选择日期时添加事件(onSelect),但无法获取日期良好的格式(ddmmyyyy)和要建立的链接。
<script type='text/javascript' >
$(document).ready(function(){
$('#mindate').datepick({
dateFormat: 'yyyy-mm-dd',
defaultDate: '2010-10-01',
minDate: '2009-10-01',
maxDate: '2010-10-01',
onSelect: function(dates) { alert('The chosen date(s): ' + dates); },
showTrigger: '<button type="button" class="trigger">Change</button>'});
});
</script>
“onSelect”给我这样的日期:所选日期:Wed Aug 25 2010 00:00:00 GMT-0400(东部夏令时间)
谢谢
I would like to add links on every date in my calendar. For example, if I click on the 25 august 2010, I would like that the page gets redirected to : xxxxxx/25082010/
(ddmmyyyy)
The plugins is this one : http://keith-wood.name/datepick.html
I can add an event when a date is selected (onSelect) but I can't get the date in the good format (ddmmyyyy) and the link to be made.
<script type='text/javascript' >
$(document).ready(function(){
$('#mindate').datepick({
dateFormat: 'yyyy-mm-dd',
defaultDate: '2010-10-01',
minDate: '2009-10-01',
maxDate: '2010-10-01',
onSelect: function(dates) { alert('The chosen date(s): ' + dates); },
showTrigger: '<button type="button" class="trigger">Change</button>'});
});
</script>
The "onSelect" give me the date like this: The chosen date(s): Wed Aug 25 2010 00:00:00 GMT-0400 (Eastern Daylight Time)
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以使用
Date
对象上的一些内置方法来格式化选择器返回的日期:You can use some of the built-in methods on the
Date
object to format the date that the picker is returning:如果还不算太晚的话,我会切换到 jQuery UI datepicker,该脚本具有更好的支持和功能 http:// /jqueryui.com/demos/datepicker/ 它有不同类型的日期和 parseDate 方法。
I'd switch to jQuery UI datepicker if it's not too late, that script has far better support and features http://jqueryui.com/demos/datepicker/ And it has different types of dates and parseDate method.
我有一个类似的问题,通过查看这个好人的答案并大喊啊哈得到了答案! jQuery DatePick 填充输入 - 多次点击问题
我希望这只是糟糕的文档,而不是我很厚(现在是我们)。
但是,问题是传递给函数的数据是数组或对象,或者在 javascript 中调用的任何垃圾,只是调用它,在您的情况下,“日期”似乎在其上运行某种 toString 。
如果你尝试约会[0],你会成为一个快乐的人。如果你有一个多选范围(我的问题),你想要日期[0]和日期[1],它只是字真的很好。我希望他能在他的文档中更清楚地说明这一点,因为我非常喜欢这个,而不是仅用于范围选择的 UI 日期选择器。
另外,如果您可以将“datepick”添加到您的标签中,我认为这会很有帮助。我浪费了很多时间试图避免所有自动认为我正在寻找 Jquery UI datapicker 而不是 Jquery datepick datepicker 的事情
I had a similar problem and got the answer by looking at this fine human being's answer and shouting aha! jQuery DatePick Populating Input - Multiple Clicks Issue
I'm hoping it's just bad documentation and not me being thick (well now us).
But, the problem is that the data passed to the function is an array or object or whatever that junk is called in javascript and just calling it, "dates" in your case seems to run some sort of toString on it.
If you try dates[0] you will be a happy man. And if you have a multi select range (my problem), you want dates[0] and dates[1] and it just words real nice. I wish he'd put this in his docs a bit more clearly as I very much prefer this one to the UI date picker just for range selecting.
Also, if you can add "datepick" to your tags I think that'd be helpful. I wasted a lot of time trying to avoid all the things that automatically think I'm looking for Jquery UI datapicker and not the Jquery datepick datepicker