admin管理员组文章数量:1323715
I have a datepicker that shows the week of the year.
What I would like to do is enable the week number, so the user can choose the week number or the day.
Example: one user picked the week 32, and other user picked 08/08/2016.
HTML code:
<label>Select Week</label>
<input type="text" id="datepicker" name="weekPicker">
Script code:
$(function(){
$( "#datepicker" ).datepicker({
showWeek: true,
firstDay: 1,
maxDate: 'today'
});
});
Working demo: /
I have a datepicker that shows the week of the year.
What I would like to do is enable the week number, so the user can choose the week number or the day.
Example: one user picked the week 32, and other user picked 08/08/2016.
HTML code:
<label>Select Week</label>
<input type="text" id="datepicker" name="weekPicker">
Script code:
$(function(){
$( "#datepicker" ).datepicker({
showWeek: true,
firstDay: 1,
maxDate: 'today'
});
});
Working demo: https://jsfiddle/iandrabedin/jhducskr/
Share Improve this question asked Aug 9, 2016 at 22:45 Iandra BedinIandra Bedin 1261 gold badge1 silver badge6 bronze badges 1- stackoverflow./questions/25746358/… – dmoo Commented Aug 9, 2016 at 23:20
1 Answer
Reset to default 4Adding an event handler to the week numbers in the beforeShow
handler will do that
$(function() {
$("#datepicker").datepicker({
showWeek: true,
firstDay: 1,
maxDate: 'today',
beforeShow: function(elem, ui) {
$(ui.dpDiv).on('click', 'tbody .ui-datepicker-week-col', function() {
$(elem).val('Week ' + $(this).text()).datepicker( "hide" );
});
}
});
});
.ui-datepicker table tbody .ui-datepicker-week-col {
cursor: pointer;
color: red
}
<script src="https://ajax.googleapis./ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://ajax.googleapis./ajax/libs/jqueryui/1.11.4/themes/smoothness/jquery-ui.css">
<script src="https://ajax.googleapis./ajax/libs/jqueryui/1.11.4/jquery-ui.min.js"></script>
<p>Click week numbers to select weeks, dates to select dates etc.</p>
<label>Select Week</label>
<input type="text" id="datepicker" name="weekPicker">
本文标签: javascriptDatepicker with week number and daysStack Overflow
版权声明:本文标题:javascript - Datepicker with week number and days - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742125476a2421919.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论