本文介绍了单击按钮后,jQuery Ready功能不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个JQuery Ready函数
I have a JQuery Ready function
$(document).ready(function () {
$('#<%= txtBlockAmount.ClientID %>').keyup(function (e) {
$(this).val(addCommasOnKeyPress($('#<%= txtBlockAmount.ClientID %>').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;
}
在页面加载时效果很好.它有一些文本框.它还具有下拉列表.当我想通过选定的下拉列表更改"加载以前的值时,它不起作用.有人知道吗?请回复.
it works nice on the page load. It has some textbox. It has also Dropdown List. When I want to Load Previous Value by Selected DropDown Change then it doesn't work. Have Anybody known?? Please Reply.
珠宝
推荐答案
可能是它在回发后失去了keyup事件.最好的选择是将其绑定到.cs page_load方法中,例如
Probably, its loosing the keyup event after postback. The best bet would be to bind it in .cs page_load method, something like
txtBlockAmount.Attributes.Add("onKeyUp", "javascript:onkeyupmethod()");
您的js函数将类似于
function onkeyupmethod()
{
$('#<%=txtBlockAmount.ClientID'%>).val(addCommasOnKeyPress($('#<%= txtBlockAmount.ClientID %>').val();
}
这篇关于单击按钮后,jQuery Ready功能不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!