87,985
社区成员




$("#ipt1").keyup(function () {
var reg = $(this).val().match(/\d+\.?\d{0,2}/);
var txt = '';
if (reg != null) {
txt = reg[0];
}
$(this).val(txt);
}).change(function () {
$(this).keypress();
var v = $(this).val();
if (/\.$/.test(v))
{
$(this).val(v.substr(0, v.length - 1));
}
});
最后的点也去掉了……$("#ipt1").keyup(function () {
var reg = $(this).val().match(/\d+\.?\d{0,2}/);
var txt = '';
if (reg != null) {
txt = reg[0];
}
$(this).val(txt);
}).change(function () {
$(this).keyup();
});
这次自测过了$("input").keypress(function () {
var reg = $(this).val().match(/\d+(\.\d{1,2})?/);
var txt = '';
if (reg != null)
{
txt = reg[0];
}
$(this).val(txt);
}).change(function () {
$(this).keypress();
});