[英]Datepicker for dynamically created controls
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 ) 对于一些动态创建的文本框,我想使用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: 通常,如果文本框控件不是动态的,我将使用以下javascript函数来调用txtBoxDate文本框的日历弹出窗口:
$(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? 由于我现在没有动态创建的文本框的ID,我如何调用jQuery日历函数?
Any ideas? 有任何想法吗?
Much appreciated! 非常感激!
EIDT: I create the controls as follows with some loop (to create multiple): EIDT:我用一些循环创建控件如下(创建多个):
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: 您可以将css类名称添加到包含日历的编辑器中,并在其上附加日期选择器,例如:
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. 对于保留此日期控件的所有编辑器,您可以使用相同的css类名,而无需更改任何其他内容。 This
$('.TheDateTimePicker')
selector will apply the "datepick" to all controls that have that css class. 这个
$('.TheDateTimePicker')
选择器将$('.TheDateTimePicker')
应用于具有该css类的所有控件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.