jQuery daterangepicker:执行警报两次?

发布于 2024-10-03 01:54:53 字数 596 浏览 3 评论 0原文

我希望它在您更改/确定日期时提醒“确定”。但我收到两个警报而不是一个?

我该如何解决这个问题?

这是代码:

$(document).ready(
function(){
   $('#datePicking')
       .daterangepicker({
       arrows:true,
       onChange: function(){
           $('#Viewer')
           alert('ok');
       }
       }); 
});

这是一个工作示例: http://jsfiddle.net/BU5PJ/2/

jquery 1.4.4、UI 1.8.5、+ 来自filamentgroup.com的日期范围选择器

I want it to alert "ok" when you change/make a date. But i get two alerts instead of one?

How can i fix this?

here's the code:

$(document).ready(
function(){
   $('#datePicking')
       .daterangepicker({
       arrows:true,
       onChange: function(){
           $('#Viewer')
           alert('ok');
       }
       }); 
});

here's a working example: http://jsfiddle.net/BU5PJ/2/

jquery 1.4.4, UI 1.8.5, + daterangepicker from filamentgroup.com

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

海之角 2024-10-10 01:54:53

从此处找到的文档来看 http://www.filamentgroup.com/lab/date_range_picker_using_jquery_ui_16_and_jquery_ui_css_framework/

onChange:函数,回调表示
每当输入日期时执行
变化(在范围内可能发生两次
选择)。

当我选择特定日期时,我只收到一个警报框。

By the looks of the documentation found here http://www.filamentgroup.com/lab/date_range_picker_using_jquery_ui_16_and_jquery_ui_css_framework/

onChange: function, callback that
executes whenever the date input
changes (can happen twice on range
selections).

When I picked a specific date I only got one alert box.

预谋 2024-10-10 01:54:53

试试这个

$(document).ready(
 function(){
 $('#datePicking')
   .daterangepicker({
   arrows:true,
   onClose : function(){
       $('#Viewer')
       alert('ok');
    }
   }); 
});

try this

$(document).ready(
 function(){
 $('#datePicking')
   .daterangepicker({
   arrows:true,
   onClose : function(){
       $('#Viewer')
       alert('ok');
    }
   }); 
});
抚笙 2024-10-10 01:54:53

就我而言,我将 daterangepicker 与 Angular 一起使用。我的目的是观察存储日期范围值的模型中的任何变化,并将其保存以供稍后 AJAX 调用。我面临同样的问题,因为每当日期更改时,即使我选择“今天”,它也会触发事件两次:一旦它是具有 startDate 和 endDate 属性的对象,另一次它是字符串

可以被用作一种优势。

    $scope.$watch(
    'rangeOfDate',
    function (newValue) {
        // Due to a known bug of open source library daterangepicker, the event is hit twice 
        //upon change. Once it is an object, and once it is a string. So, use appropriately.
        var selectedDateRange = new Object();
        if (typeof (newValue) == 'object') {
            selectedDateRange.startDate = new Date(newValue.startDate).toLocaleDateString();
            selectedDateRange.endDate = new Date(newValue.endDate).toLocaleDateString();
            //Do as you wish with this custom object
        }
        else if (typeof (newValue) == 'string') {
            alert("string");
        }               
    },
    false);

In my case, I am using daterangepicker with angular. My purpose is to watch any change in the model that stores the date range value and save it for an AJAX call later. I face the same issue as it hits the event twice whenever the date is changed even if I select 'Today': Once it is object with startDate and endDate properties, and the other time it is a string.

It can be made use of as an advantage.

    $scope.$watch(
    'rangeOfDate',
    function (newValue) {
        // Due to a known bug of open source library daterangepicker, the event is hit twice 
        //upon change. Once it is an object, and once it is a string. So, use appropriately.
        var selectedDateRange = new Object();
        if (typeof (newValue) == 'object') {
            selectedDateRange.startDate = new Date(newValue.startDate).toLocaleDateString();
            selectedDateRange.endDate = new Date(newValue.endDate).toLocaleDateString();
            //Do as you wish with this custom object
        }
        else if (typeof (newValue) == 'string') {
            alert("string");
        }               
    },
    false);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文