JQuery:委托和datepicker [英] JQuery: delegate and datepicker

查看:88
本文介绍了JQuery:委托和datepicker的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要给定类中的每个文本输入都是一个日期选择器。类似于:

I need that every text input in a given class is a datepicker. Something like:

$("input[type=text].time").datepicker();

但是我通过Jquery.load()添加了很多代码所以我相信我需要一个代表。问题是我不知道该怎么做,因为据我所知,load事件不能在委托中使用。它会很容易存在:

but I'm adding a lot of code via Jquery.load() so I believe I need a delegate. The problem is I don't know how to do it, because as far as I know, load event cannot be used in a delegate. It will be easy if it exists:

$(document).delegate("input[type=text].time", "load", function(){
    $(this).datepicker();
});


推荐答案

$("body").delegate("input[type=text].time", "focusin", function(){
   $(this).datepicker();
});

我在身体上使用了委托,因为我不知道你的代码是否在其他容器中你可以定位。

I used delegate on the body because I don't know if you have your code in other containers that you can target.

这是一个小提琴,它使用委托来定位特定的 div

Here is a fiddle that targets a specific div with delegate:

http://jsfiddle.net/MpqAy/

这篇关于JQuery:委托和datepicker的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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