我有两个动态创建的文本框(txtFrom& txtTo)来自服务器端代码。我想调用这些文本框的jquery函数onmouseup事件。我怎么能这样做。我的jquery函数如下所示。
<script type="text/javascript">
$(document).ready(function() {
$('#txtFrom').datepicker({
//appendText:'mm/dd/yyyy',
showOn: 'both',
buttonText: '..',
dateFormat: 'dd/mm/yy',
//numberOfMonths:2,
changeMonth: true,
changeYear: true,
minDate: new Date(2017, 4, 1),
maxDate: new Date(2025, 3, 31)
});
});
在期待中感谢你。
动态添加文本框的代码如下:
protected void getDateControls()
{
foreach (GridViewRow grow in gdView.Rows)
{
System.Web.UI.WebControls.TextBox txtFrom = new
System.Web.UI.WebControls.TextBox();
txtFrom.ID = "txtFrom";
txtFrom.Width = 70;
txtFrom.AutoPostBack = true;
txtFrom.TextChanged += new
System.EventHandler(this.txtFrom_Changed);
grow.Cells[5].Controls.Add(txtFrom);
System.Web.UI.WebControls.TextBox txtTo = new
System.Web.UI.WebControls.TextBox();
txtTo.ID = "txtTo";
txtTo.Width = 70;
enter code heretxtTo.AutoPostBack = true;
txtTo.TextChanged += new System.EventHandler(this.txtTo_Changed);
grow.Cells[6].Controls.Add(txtTo);
}
}
我想让jquery函数调用这些文本框的onclick或onmouseup事件。
答案 0 :(得分:0)
您只需使用Jquery.on来挂钩动态控件的事件
尝试以下代码
<script type="text/javascript">
$(document).ready(function() {
$(document).on("click","input[id*='txtFrom']",function(){ //whatever code you want });
$(document).on("click","input[id*='txtTo']",function(){ //whatever code you want });
});
</script>
注意:如果有人要求您显示您的代码,则需要更新您的代码 问题而不是添加答案。请删除它。