鼠标滚轴控制文本框值的JS代码
鼠标滚轴控制文本框值的JS代码
发布时间:2016-12-30 来源:查字典编辑
摘要:复制代码代码如下:/*根据获得焦点的时候给setVal给值*/varsetVal;varbool=false;varscrollFunc=f...

复制代码 代码如下:

<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>

推荐文章
猜你喜欢
附近的人在看
推荐阅读
拓展阅读
相关阅读
网友关注
最新Javascript教程学习
热门Javascript教程学习
编程开发子分类