onpropertychange在IE8下的bug

默默不得鱼 2011-10-10 02:07:57
写了个控制文本框输入的方法,发现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>
...全文
153 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
maniacstone 2011-11-11
  • 打赏
  • 举报
回复
答案已发到你邮箱。
默默不得鱼 2011-10-21
  • 打赏
  • 举报
回复
谁能给个完美的解决方案?
默默不得鱼 2011-10-10
  • 打赏
  • 举报
回复
给文本框加了 style="width:75px;"之后又不行了 求解
默默不得鱼 2011-10-10
  • 打赏
  • 举报
回复
给文本框加上padding:0;之后就正常了
求原因

87,901

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧