onpropertychange在IE8下的bug

默默不得鱼 默默不得鱼 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
写了个控制文本框输入的方法,发现IE8下有bug
onpropertychange事件总是隔一次才会触发(1,3,5..次输入才会触发)
加上样式部分代码就正常了,诸位可以试一下
<style type="text/css">
*{ margin: 0; padding: 0; } </style>



<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<script src="../script/jquery-1.6.2.min.js" type="text/javascript"></script>

<script type="text/javascript">
$.fn.extend({
decimal: function(len, x) {
var str;
if (x == 0) {
str = "^(?!0{2,})(?!0\\d+)\\d{0," + len + "}$"; //小数位0
} else if (x == 1) {//小数位1
str = "^(?!0{2,})(?!0\\d+)(?:\\d{1," + (len - x) + "}\\.?[\\d+]{0," + x + "})(?!\\.)$";
} else {//decimal(12,2) 有效长度12,小数位2
str = "^(?!0{2,})(?!0\\d+)(?:\\d{1," + (len - x) + "}\\.?[\\d+]{0," + x + "}|\\d{1," + ((len - x) + 1) + "}\\.?[\\d+]{0," + (x - 1) + "})(?!\\.)$";
}
var reg = new RegExp(str);
this.bind("propertychange", function() {
if (this.value.length > 0) {
if (!reg.test(this.value)) {
this.value = this.value.substring(0, this.value.length - 1);
}
}
return true;
});
return this;
}
});
window.onload = function() {
$("input[type='text']").decimal(3, 0);
};
</script>
</head>
<body>
<input type="text" />
</body>
</html>
...全文
评论 7
收藏 已收藏
分享
返回顶部
默默不得鱼
JavaScript 87,984 成员 224,681 内容