单击按钮后,JQuery Readyfunction不起作用

我有一个JQuery Readyfunction

$(document).ready(function () { $('#').keyup(function (e) { $(this).val(addCommasOnKeyPress($('#').val())); }); }); function addCommasOnKeyPress(nStr) { nStr = nStr.replace(/\,/g, '') nStr += ''; var x = nStr.split('.'); var x1 = x[0]; var x2 = x.length > 1 ? '.' + x[1] : ''; var rgx = /(\d+)(\d{3})/; while (rgx.test(x1)) { x1 = x1.replace(rgx, '$1' + ',' + '$2'); } return x1 + x2; } 

它在页面加载时效果很好。 它有一些文本框。 它还有下拉列表。 当我想通过选择的DropDown Change加载以前的值时,它不起作用。 有人知道吗? 请回复。

可能是它在回发后失去了keyup事件。 最好的办法是将它绑定在.cs page_load方法中

 txtBlockAmount.Attributes.Add("onKeyUp", "javascript:onkeyupmethod()"); 

你的jsfunction看起来像

 function onkeyupmethod() { $('#<%=txtBlockAmount.ClientID'%>).val(addCommasOnKeyPress($('#<%= txtBlockAmount.ClientID %>').val(); } 

试试这个:

 var textb = $('#<%=TextBox.ClientID'%>); $(document).ready(function () { textb.keyup(function (e) { this.val(CustomizeFunction(textb.val())); }); });