js鼠标滚轴控制文本框值
作者:互联网
本代码执行效果是,当用户点击把焦点给文本框时候,通过滚动鼠标滚轴,可以增加值和减小值
<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" οnfοcus="ufocus(this)" οnblur="ublur(this)"/>
</body>
</html>
标签:setVal,num1,文本框,js,var,bool,滚轴,ew,else 来源: https://blog.51cto.com/u_14943622/2834963