jQuery live()与jQuery UI datepicker失败 [英] jQuery live() failing with jQuery UI datepicker

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

问题描述

好的,我试图用jQuery的FaceBox()插件和jQuery UI的datepicker()。



我已经把它绑定到在灯箱的第一个外观lightbox'd输入,但它不工作之后。

我做了以下:
$(this).datepicker {showOn:'both'})。focus();
});
});



当灯箱关闭时,我将它的内容重新添加到页面为了不丢失内容div),这似乎是杀死live()调用。 [注:在原始内容被销毁后重新追加

编辑



好的,live()事件正在触发(感谢Nick Craver),但是datepicker不再显示。有没有人有一个想法为什么?

编辑#2



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




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

解决方案

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

如果您在jQuery 1.4中使用jQuery UI 1.7.2,某些效果将会消除小部件, ,等可能会导致datepicker问题。 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 datepicker失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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