简体   繁体   English

如何调用bootstrap3-datetimepicker的“ onSelect”功能? jQuery的

[英]How to call “onSelect” function for bootstrap3-datetimepicker? jQuery

I am using Rails 4 and I have the gem bootstrap3-datetimepicker-rails installed. 我正在使用Rails 4,并且安装了gem bootstrap3-datetimepicker-rails

It is working fine, but I want to be able to do an onSelect call like I can with the normal bootstrap-datepicker. 它工作正常,但我希望能够像使用常规bootstrap-datepicker一样进行onSelect调用。

I want to be able to do something like this: 我希望能够做这样的事情:

$("#start").datetimepicker({
    minDate: new Date()
}).on("change", function(selectedDate) {
    $("#end").datetimepicker({ minDate: selectedDate });
});

$("#end").datetimepicker();

but the documentation is very vague and doesn't seem to include anything on this concept. 但是文档非常模糊,似乎没有包含有关此概念的任何内容。 I am still pretty surprised that this feature of validating start and end dates is not a native option in any date or time picker. 我仍然很惊讶,验证日期和结束日期的功能不是任何日期或时间选择器中的本机选项。

How would I realize this? 我将如何实现?

Note : I am using bootstrap3-date time picker, not the regular bootstrap-datepicker and not jquery-datetimepicker. 注意 :我使用的是bootstrap3-date 时间选择器,而不是常规的bootstrap-datepicker,而不是jquery-datetimepicker。

Side Note: I've always felt that the world's most ideal automatic datepicker validation would look something like this: 旁注:我一直觉得世界上最理想的自动日期选择器验证看起来像这样:

$("#start").datepicker({
    minDate: new Date(),
    endDate: "#end"  // Would automatically call $("#end").datepicker and set the minDate to whatever #start's selected date is
});

I am considering creating my own branch to try and implement it because I feel that the concept of start and end dates is commonly ignored when datepickers are created but is so frequently needed. 我正在考虑创建自己的分支来尝试实现它,因为我觉得创建日期选择器时通常会忽略开始日期和结束日期的概念,但这种需求非常频繁。

Take a look at the documentation section on linked pickers: https://eonasdan.github.io/bootstrap-datetimepicker/#linked-pickers 看一下链接选择器的文档部分: https : //eonasdan.github.io/bootstrap-datetimepicker/#linked-pickers

In your case you would do: 您的情况是:

$("#start").on("dp.change", function (e) {
    $('#end').data("DateTimePicker").minDate(e.date);
});

Try this, 尝试这个,

$("#start").datetimepicker({
    minDate: new Date()
}).on("change.dp", function(selectedDate) {
    $("#end").datetimepicker({ minDate: selectedDate });
});

If not, try this, 如果没有,请尝试

$("#start").datetimepicker({
        minDate: new Date()
    }).on("dp.change", function(selectedDate) {
        $("#end").datetimepicker({ minDate: selectedDate });
    });

Check bootstrap-3-datetimepicker-events-not-firing-up for more info 检查bootstrap-3-datetimepicker-events-not-firing-up以获取更多信息

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Jquery Datepicker onselect调用函数 - Jquery Datepicker onselect call function meteor.js如何在“ tsega:bootstrap3-datetimepicker”包中选择禁止追溯日期 - meteor.js How to choose prohibit retroactive date in the package “tsega:bootstrap3-datetimepicker” 如何调用datepicker jQuery的js函数onSelect事件? - How to call a js function onSelect event of datepicker jquery? TypeError:在Meteor应用程序中使用tsega:bootstrap3-datetimepicker时,无法读取未定义的属性“ date” - TypeError: Cannot read property 'date' of undefined when using tsega:bootstrap3-datetimepicker in Meteor app meteor.js“ tsega:bootstrap3-datetimepicker”使用SimpleSchema“ type:Date”记录数据 - meteor.js “tsega:bootstrap3-datetimepicker” record data using the SimpleSchema “type: Date” jQuery .on('click',function())无法与bootstrap-datetimepicker一起使用 - jQuery .on('click', function()) not working with bootstrap-datetimepicker jQuery datepicker onSelect不会在Internet Explorer中调用自定义函数 - jquery datepicker onSelect won't call custom function in Internet Explorer 如何在 jQuery DateRangePicker 的 OnChange 或 OnSelect 事件后调用 Ajax? - How to call Ajax after OnChange or OnSelect event in jQuery DateRangePicker? 无法在自定义指令中调用jquery datetimepicker函数 - unable to call jquery datetimepicker function in custom directive Bootstrap DateTimePicker和jQuery问题 - Bootstrap DateTimePicker and jQuery problems
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM