jQuery live() 使用 jQuery UI 日期选择器失败 [英] jQuery live() failing with jQuery UI datepicker

查看:34
本文介绍了jQuery live() 使用 jQuery UI 日期选择器失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,我正在尝试将 jQuery 的 FaceBox() 插件与 jQuery UI datepicker() 一起使用.

我已经让它在灯箱第一次出现时绑定到灯箱的输入,但之后它不起作用.

我正在做以下事情:<代码><预>$(函数(){$('.jQueryCalendar').live('click', function () {$(this).datepicker({showOn: 'both'}).focus();});});

当灯箱关闭时,我将它的内容重新附加到页面上(为了不丢失内容 div),这似乎杀死了 live() 调用.[注意重新追加发生在原始内容被破坏之后]

编辑

好的,live() 事件正在触发(感谢 Nick Craver),但是不再显示日期选择器.有谁知道为什么?

编辑#2

好的,使用 .html() 重新追加会导致事件需要重新绑定,但要绑定的元素仍然具有类 hasDatepicker,这与 datepicker() 初始化混乱.

要修复,只需用户<代码><预>$(this).removeClass('hasDatepicker') .datepicker({showOn: 'both'}).focus();

解决方案

试试这个,看看会发生什么:

$(function() {$('.jQueryCalendar').live('click', function () {$(this).datepicker('destroy').datepicker({showOn: 'both'}).focus();});});

如果您将 jQuery UI 1.7.2 与 jquery 1.4 一起使用,某些效果会破坏小部件、褪色等可能会导致日期选择器问题.jQuery UI 1.8 修复了这个问题,目前处于 RC3 状态.

Ok, I'm trying to use the FaceBox() plugin for jQuery along with the jQuery UI datepicker().

I've got it to bind to the lightbox'd inputs on the first appearance of the lightbox, but it's not working afterwards.

I'm doing the following:

$(function() { 
    $('.jQueryCalendar').live('click', function () {
            $(this).datepicker({showOn: 'both'}).focus();
    });
});

When the lightbox closes, I'm re-appending it's content to the page (in order to not lose the content div), and this seems to be killing the live() call. [NB the re-appending takes place after the original content is destroyed]

EDIT

Ok, the live() event IS firing (thanks to Nick Craver for that), however the datepicker is no longer being shown. Does anyone have an idea why?

EDIT #2

Ok, the use of .html() to re-append causes the events to need rebinding, but the element to bind still has the class hasDatepicker, which messes with the datepicker() initialisation.

To fix, simply user

$(this).removeClass('hasDatepicker') .datepicker({showOn: 'both'}).focus();

解决方案

Try this and see what happens:

$(function() { 
    $('.jQueryCalendar').live('click', function () {
            $(this).datepicker('destroy').datepicker({showOn: 'both'}).focus();
    });
});

If you're using jQuery UI 1.7.2 with jquery 1.4, some effects destroy widgets, it fading, etc may be causing datepicker issues. jQuery UI 1.8 fixes this, it's at RC3 Status at the moment.

这篇关于jQuery live() 使用 jQuery UI 日期选择器失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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