Jquery .live工作,但没有.datepicker [英] Jquery .live works but not with .datepicker

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

问题描述

感谢您的看法,所有真诚有用的答案都被高估了。
我有一些日期输入字段,当页面加载和一堆动态生成的页面。每次生成一个新的实例时,而不是在该类上调用.datepicker(),我使用的是.live,但是似乎不起作用。任何想法为什么?

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

我应该提到,它可以完美地运行,例如自动完成。

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


解决方案

这是一篇关于使用.live - jQuery中的事件:



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



问题是,Datepicker默认情况下绑定到focus()事件,但是从jQuery 1.3.2开始,'focus'事件不能被'live'事件功能监视。



这是网站的解决方法::

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






编辑:此解决方法已不再需要jQuery 1.4.1+现在支持focus()模糊事件为live()。 (感谢 @Chris S


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");
});

解决方案

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/

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>


EDIT: This workaround is no longer needed as jQuery 1.4.1+ now supports focus and blur events for live(). (Thanks @Chris S)

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

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