代码很简单,都加了注释,就不知道实现的够不够科学,如果你有更好的建议不妨与我分享。HTML与JavaScript代码如下: 变速加数功能实现 按住按钮不放,数值将会越加越快 /** * 加数类 * @param {String} textBoxId 文本框ID */ function clsAddNum(textBoxId) { var step = 1; //默认步长 var changeStepTimer = null; //改变速度计数器 var setValueTimer = null; //设置值计数器 /** * 改变速度私有方法 */ var changeStep = function() { //每隔1秒速度加5 changeStepTimer = setInterval(function(){step += 5}, 1000); } /** * 设置值私有方法 */ var setValue = function() { var textValue = parseInt(document.getElementById(textBoxId).value); document.getElementById(textBoxId).value = textValue + step; setValueTimer = setTimeout(setValue,200); //每隔200毫秒更新文本框数值一次 } /** * 按下鼠标处理函数 */ this.mouseDownHandle = function() { changeStep(); setValue(); } /** * 松开鼠标处理函数 */ this.mouseUpHandle = function() { //停止变速和改变文本框的值 clearInterval(changeStepTimer); clearTimeout(setValueTimer); step = 1; //恢复默认速度 } } //实例化类 var addNum = new clsAddNum('textBox'); script> [Ctrl+A 全选 注:如需引入外部Js需刷新才能执行]作者:WebFlash 出处:http://webflash.cnblogs.com