Bootstrap Datepicker触发器更改 [英] Bootstrap datepicker trigger change

查看:46
本文介绍了Bootstrap Datepicker触发器更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有使用引导日期选择器输入和输入的字段.当查询参数不为空时,我想更改这些输入字段的值并在datepicker上触发更改日期事件,因为我有一个计算日期之间总价的函数.当用户从datepicker中选择日期时,效果很好,但是如果我通过jquery更改值,则不会计算.

I have from and to input fields with bootstrap date picker. When query params not empty I would like to change the value of these input fields and trigger the change date event on datepicker because I have a function that calculates total price between dates. When user selects dates from datepicker works fine but if I change the value by jquery it does not calculate.

$('#from').val('<%= @from_date %>').trigger( 'change' );
$('#to').val('<%= @to_date %>').trigger( 'change' );
//function
var dates_avail = new DatesAvailability({
                start: '#from',
                end: '#to'
});

..
W.DatesAvailability = function (opts) {
var options = $.extend({}, defaultOpts, opts);
        var start = options.start + ',' + options.rel_start;
        var end = options.end + ',' + options.rel_end;
        $(start + ',' + end).datepicker({
            autoclose: true,
            format: "yyyy-mm-dd",
            startDate: '+1d',
            endDate: '+3y',
..
}).
on('changeDate', function (e) {
// I would like to trigger this.
..

bootstrap-datepicker.js中也有这些行

I also have these lines in bootstrap-datepicker.js

..
if (fromArgs){
                // setting date by clicking
                this.setValue();
                this.element.change();
            }
            else if (this.dates.length){
                // setting date by typing
                if (String(oldDates) !== String(this.dates) && fromArgs) {
                    this._trigger('changeDate');
                    this.element.change();
                }
            }
..

推荐答案

尝试使用

Try using the update mention in the documentation. Something like `$(start + ',' + end).datepicker('update', qParamStart);

如果您想弄清楚如何获取查询参数,请

If you're trying to figure out how to get the query params this is a good reference.

这篇关于Bootstrap Datepicker触发器更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆