jQuery 日期选择器,onSelect 不起作用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/887696/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
jQuery datepicker, onSelect won't work
提问by Tommy Jakobsen
I can't get onSelect
working on my jQuery datepicker
.
我无法onSelect
处理我的 jQuery datepicker
。
Heres my code:
这是我的代码:
<script type="text/javascript">
$(function() {
$('.date-pick').datePicker( {
onSelect: function(date) {
alert(date)
},
selectWeek: true,
inline: true,
startDate: '01/01/2000',
firstDay: 1,
});
});
</script>
It's like it doesn't register the onSelect
function. What am I doing wrong?
就像它没有注册该onSelect
功能一样。我究竟做错了什么?
回答by Antony Carthy
No comma after the last property.
最后一个属性后没有逗号。
Semicolon after alert(date);
警报后的分号(日期);
Case on datepicker (not datePicker)
datepicker 上的案例(不是 datePicker)
Check your other uppercase / lowercase for the properties.
检查其他大写/小写的属性。
$(function() {
$('.date-pick').datepicker( {
onSelect: function(date) {
alert(date);
},
selectWeek: true,
inline: true,
startDate: '01/01/2000',
firstDay: 1
});
});
回答by Ben Koehler
datePicker's onSelect equivalent is the dateSelected event.
datePicker 的 onSelect 等价物是 dateSelected 事件。
$(function() {
$('.date-pick').datePicker( {
selectWeek: true,
inline: true,
startDate: '01/01/2000',
firstDay: 1,
}).bind('dateSelected', function(e, selectedDate, $td) {
alert(selectedDate);
});
});
This pagehas a good example showing the dateSelected event and other events being bound.
这个页面有一个很好的例子,显示了 dateSelected 事件和其他被绑定的事件。
回答by Z.Y
$('.date-picker').datepicker({
autoclose : true,
todayHighlight : true,
clearBtn: true,
format: 'yyyy-mm-dd',
onSelect: function(value, date) {
alert(123);
},
todayBtn: "linked",
startView: 0, maxViewMode: 0,minViewMode:0
}).on('changeDate',function(ev){
//this is right events ,trust me
}
});
回答by Itamar
The best solution is to set the datepicker defaults
最好的解决方案是设置日期选择器默认值
folows the code that I used
按照我使用的代码
$.datepicker.setDefaults({
onSelect: function () {
$(this).focus();
$(this).nextAll('input, button, textarea, a').filter(':first').focus();
}
});
回答by Judy
<script type="text/javascript">
$(function() {
$("#datepicker").datepicker({
onSelect: function(value, date) {
window.location = 'day.jsp' ;
}
});
});
</script>
<div id="datepicker"></div>
I think you can try this .It works fine .
我想你可以试试这个。它工作正常。
回答by samjudson
The function datepicker
is case sensitive and all lowercase. The following however works fine for me:
该函数datepicker
区分大小写且全部小写。然而,以下对我来说很好:
$(document).ready(function() {
$('.date-pick').datepicker( {
onSelect: function(date) {
alert(date);
},
selectWeek: true,
inline: true,
startDate: '01/01/2000',
firstDay: 1
});
});
回答by srilatha
I have downloaded the datepicker from jqueryui.com/download and I got 1.7.2 version but still onSelect function didn't work. Here is what i had -
我已经从 jqueryui.com/download 下载了 datepicker 并且我得到了 1.7.2 版本但仍然 onSelect 功能不起作用。这是我所拥有的 -
$("#datepicker").datepicker();
$("#datepicker").datepicker({
onSelect: function(value, date) {
alert('The chosen date is ' + value);
}
});
I found the solution in this page -- problem with jquery datepicker onselect. Removed the $("#datepicker").datepicker(); once and it worked.
我在此页面中找到了解决方案 - jquery datepicker onselect 的问题。删除了 $("#datepicker").datepicker(); 一次,它奏效了。
回答by tvanfosson
It should be "datepicker", not "datePicker" if you are using the jQuery UI DatePicker plugin. Perhaps, you have a different but similar pluginthat doesn't support the select handler.
如果您使用的是 jQuery UI DatePicker 插件,它应该是“datepicker”,而不是“datePicker”。也许,您有一个不支持选择处理程序的不同但相似的插件。