概述
<html>
<head>
<title></title>
<script type="text/javascript" language="javascript">
/*根据获得焦点的时候给setVal给值*/
var setVal;
var bool = false;
var scrollFunc=function(e){
var direct=0;
e=e || window.event;
var ew = e.wheelDelta
if(ew && bool){
if(ew > 0){
var num1 = setVal.value;
if(num1 > 0){
num1 = eval(1+parseInt(num1));
}else{
num1 = 1;
}
}else{
var num1 = setVal.value;
if(num1 > 0){
num1 = eval(parseInt(num1)-1);
}else if(num1 == 0){
num1 = 0;
}else{
num1 = 1;
}
}
setVal.value = num1;
}
}
window.onmousewheel=document.onmousewheel=scrollFunc;
function ufocus(eve){
bool = true;
setVal = eve;
}
function ublur(){
bool = false;
setVal = null;
}
</script>
</head>
<body>
<input type="text" onfocus="ufocus(this)" onblur="ublur(this)"/>
</body>
</html>
<html>
<head>
<title></title>
<script type="text/javascript" language="javascript">
/*根据获得焦点的时候给setVal给值*/
var setVal;
var bool = false;
var scrollFunc=function(e){
var direct=0;
e=e || window.event;
var ew = e.wheelDelta
if(ew && bool){
if(ew > 0){
var num1 = setVal.value;
if(num1 > 0){
num1 = eval(1+parseInt(num1));
}else{
num1 = 1;
}
}else{
var num1 = setVal.value;
if(num1 > 0){
num1 = eval(parseInt(num1)-1);
}else if(num1 == 0){
num1 = 0;
}else{
num1 = 1;
}
}
setVal.value = num1;
}
}
window.onmousewheel=document.onmousewheel=scrollFunc;
function ufocus(eve){
bool = true;
setVal = eve;
}
function ublur(){
bool = false;
setVal = null;
}
</script>
</head>
<body>
<input type="text" onfocus="ufocus(this)" onblur="ublur(this)"/>
</body>
</html>
最后
以上就是高贵网络为你收集整理的鼠标滚轴控制文本框值的JS代码的全部内容,希望文章能够帮你解决鼠标滚轴控制文本框值的JS代码所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复