日期选择器动态创建的控件 [英] Datepicker for dynamically created controls
问题描述
我有一个网页一些动态控件。
对于一些动态创建的文本框,我想使用jQuery(基思·伍德<添加日历控件/ A>)
通常,如果文本框控件不是动态的,我有以下的JavaScript函数上的txtBoxDate文本框的日历弹出来电:
$(函数(){
$('#&LT;%= txtBoxDate.ClientID%GT;')datepick({DATEFORMAT:'年月日'});
});
因为我不现在我的动态创建的文本框,我怎么了jQuery日历功能调用的ID?
任何想法?
大部分AP preciated!
EIDT:我创建控件的一些循环如下(创建多个):
TR的TableRow =新的TableRow();
TableCell的TD1 =新的TableCell();
TableCell的TD2 =新的TableCell();文本框txtValue =新的TextBox();
txtValue.Width = 250;
txtValue.ID =textbox_+ dt.Rows [j]的[2]的ToString();
您可以添加CSS类名称编辑器持有的日历和连接上的日期选择器的基础,例如:
文本框txtValue =新的TextBox();
txtValue.Width = 250;
txtValue.CssClass =TheDateTimePicker;
和脚本:
$(函数(){
$('。TheDateTimePicker')datepick({DATEFORMAT:'年月日'});
});
您可以为所有保持这个日期的控制,没有改变任何东西的编辑器都使用相同的CSS类名。这 $('。TheDateTimePicker')
选择将应用datepick到有CSS类的所有控件。
I have a page with a number of dynamic controls.
For some of the dynamically created textboxes, I'd like to add calendar control using jQuery (Keith Wood)
Normally, if the textbox controls are not dynamic, I would have the following javascript function to call on the calendar popup for the txtBoxDate textbox:
$(function () {
$('#<%=txtBoxDate.ClientID%>').datepick({ dateFormat: 'dd MM yyyy' });
});
Since I don't now the IDs of my dynamically created textboxes, how do I call on the jQuery calendar function?
Any ideas?
Much appreciated!
EIDT: I create the controls as follows with some loop (to create multiple):
TableRow tr = new TableRow();
TableCell td1 = new TableCell();
TableCell td2 = new TableCell();
TextBox txtValue = new TextBox();
txtValue.Width = 250;
txtValue.ID = "textbox_" + dt.Rows[j][2].ToString();
You can add a css Class name to your editor that hold the Calendar and attach the datepicker base on that, eg:
TextBox txtValue = new TextBox();
txtValue.Width = 250;
txtValue.CssClass = "TheDateTimePicker";
and on script:
$(function () {
$('.TheDateTimePicker').datepick({ dateFormat: 'dd MM yyyy' });
});
You can use the same css class name for all the editors that keep this date control, without change anything else. This $('.TheDateTimePicker')
selector will apply the "datepick" to all controls that have that css class.
这篇关于日期选择器动态创建的控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!