[英]Format a string using a string pattern
I have a displayFormat pattern "$###,###,###;-$###,###,###;#" (it can be different too) and I want to reformat the value in the AspxTextbox after deleting the ',' on GotFocus<\/code> and
LostFocus<\/code> events by calling the following JavaScript function :
我有一个 displayFormat 模式 "$###,###,###;-$###,###,###;#" (它也可以不同),我想重新格式化通过调用以下 JavaScript 函数删除
GotFocus<\/code>和
LostFocus<\/code>事件上的“,”后的 AspxTextbox:
function TextBoxFormat(ctrl, e, displayFormat, charactersToRemove) {
var value = ctrl.GetValue();
var i;
if (value != null && charactersToRemove != null) {
for (i = 0; i < charactersToRemove.length; i++)
value = value.replace(charactersToRemove[i], '');
ctrl.SetValue(ASPxFormatter.Format('{0:' + displayFormat + '}',
parseInt(value)));
}
The MaskedEdit in the ajax control toolkit looks very much like what you want to do. ajax控件工具箱中的MaskedEdit看起来非常类似于您想要执行的操作。 If you don't want to use the pre-built controls, you can get the javascript source in one of the download packages. 如果您不想使用预先构建的控件,则可以从其中一个下载包中获取javascript源。
Here is the format function...这是格式功能...
String.format = function() { var s = arguments[0]; for (var i = 0; i < arguments.length - 1; i++) { var reg = new RegExp("\\\\{" + i + "\\\\}", "gm"); s = s.replace(reg, arguments[i + 1]); } return s; }<\/code><\/pre>
"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.