Jquery .live 有效但不适用于 .datepicker [英] Jquery .live works but not with .datepicker

查看:25
本文介绍了Jquery .live 有效但不适用于 .datepicker的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

感谢您的关注,所有真诚有帮助的答案都已投赞成票.我有一些页面加载时的日期输入字段和一些动态生成的字段.每次生成新实例时,我没有在该类上调用 .datepicker(),而是使用 .live,但它似乎不起作用.知道为什么吗?

Thanks for looking, all sincerely helpful answers are up-voted. I have some date input fields that are there when the page loads and a bunch that get generated dynamically. Instead of calling .datepicker() on that class each time a new instance is generated, I'm using .live, but it doesn't seem to be working. Any idea why?

$("input[name=myfav]").live("click", function(){
    $(this).datepicker({ 
        /* some options here */ 
    });
});

我应该提到,例如,它与自动完成功能完美结合.

I should mention, it works perfectly fine with autocomplete for instance.

$("input[name=mytwo]").live("click", function(){
    $(this).autocomplete("somefile.php");
});

推荐答案

这是一篇关于在 jQuery 中使用 .live-event 的日期选择器的文章:

Here is an article about the datepicker using the .live-event in jQuery:

http://www.vancelucas.com/blog/jquery-ui-datepicker-with-ajax-and-livequery/

问题是 Datepicker 默认通过绑定到 focus() 事件来工作,但从 jQuery 1.3.2 开始,'focus' 事件不能被'live' 事件函数监控.

The problem is that the Datepicker works by binding to the focus() event by default, but as of jQuery 1.3.2, the ‘focus’ event cannot be monitored by the ‘live’ event function.

这是该站点的解决方法::

Here is the work-around from the site::

<script type="text/javascript">
$(function(){
    $('input.calendarSelectDate').live('click', function() {
        $(this).datepicker({showOn:'focus'}).focus();
    });
});
</script>

<小时>

不再需要此解决方法,因为 jQuery 1.4.1+ 现在支持 live() 的焦点和模糊事件.(感谢 @Chris S)

这篇关于Jquery .live 有效但不适用于 .datepicker的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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