onpropertychange在IE8下的bug
写了个控制文本框输入的方法,发现IE8下有bug
onpropertychange事件总是隔一次才会触发(1,3,5..次输入才会触发)
加上样式部分代码就正常了,诸位可以试一下
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>
...全文
相关推荐
兼容Firefox和IE的onpropertychange事件oninput
onpropertychange能够捕获每次输入值的变化。例如:对象的value值被改变时,onpropertychange能够捕获每次改变,而onchange需要执行某个事件才可以捕获。
oninput,onpropertychange,onchange的用法和区别
oninput,onpropertychange,onchange的用法和区别
JavaScript的onpropertychange事件
NULL 博文链接:https://hongan.iteye.com/blog/286251
onchange和onpropertychange
NULL 博文链接:https://669341085.iteye.com/blog/905300
javascript开发中使用onpropertychange,oninput事件解决onchange事件的不足
用onpropertychange,oninput事件解决onchange事件的不足,需要的朋友可以参考下。


