onkeyup 包含两个事件

来源:百度知道 编辑:UC知道 时间:2024/07/05 04:20:15
有两个事件,想包含在onkeyup里面,不知道该怎么写.
一个是响应JS的 onkeyup="listsumNumber("nm1")" 这个是计算文体框数字用的
另一个是限制文本框只能输入数字:
onKeyUp="value=value.replace(/[^\d.]/g,'')" onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\d.]/g,''))"

我想将前面一个事件合并到第二个事件.能写吗?怎么操作.
onkeyup="listsumNumber("nm1");value=value.replace(/[^\d.]/g,'')" onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\d.]/g,''))"

<html>
<body>
<input type="button" id="button_test" value="测试" />
<script type="text/javascript">
function addEventHandler(target, type, func) {
if (target.addEventListener)
target.addEventListener(type, func, false);
else if (target.attachEvent)
target.attachEvent("on" + type, func);
else target["on" + type] = func;
}

addEventHandler(document.getElementById("button_test"), "click", function () { alert(1); });
addEventHandler(document.getElementById("button_test"), "click", function () { alert(2); });
</script>
</body>
</html>