function select_getIndex(obj,e) {
var theIndex ;
try{
theIndex = Math.floor((event.offsetY+obj.scrollTop)/(obj.offsetHeight/obj.size));
}
catch(err)
{
theIndex = Math.floor((e.layerY+obj.scrollTop)/(obj.clientHeight/obj.size));
}
//alert(theIndex);
if(theIndex<0)theIndex=0;
else if(theIndex>obj.options.length)theIndex=obj.options.length;
// alert(obj.selectedIndex);
return theIndex;
}
<select id='coupon_types' name='counpon_type_name[]' style="width:220px;" size="5"
onmousedown="select_mouseDown(this,event);"
onmousemove="select_mouseMove(this,event);"
onmouseup="select_mouseUp(this,event);"
>
<option value='1'>1</option>
<option value='2'>2</option>
<option value='3'>3</option>
<option value='4'>4</option>
<option value='5'>5</option>
<option value='6'>6</option>
<option value='7'>7</option>
</select>
-----------------------------
这里的函数是分别获得在IE和FIREFOX下当前鼠标位置的OPTION选项在数组中的位置
1-5的位置能够准确得到,因为SELECT的SIZE被设置成了5.而6,7因为需要滑块拖动的关系,得不到正确的位置.
希望有达人能告诉我错在哪里.
var theIndex ;
try{
theIndex = Math.floor((event.offsetY+obj.scrollTop)/(obj.offsetHeight/obj.size));
}
catch(err)
{
theIndex = Math.floor((e.layerY+obj.scrollTop)/(obj.clientHeight/obj.size));
}
//alert(theIndex);
if(theIndex<0)theIndex=0;
else if(theIndex>obj.options.length)theIndex=obj.options.length;
// alert(obj.selectedIndex);
return theIndex;
}
<select id='coupon_types' name='counpon_type_name[]' style="width:220px;" size="5"
onmousedown="select_mouseDown(this,event);"
onmousemove="select_mouseMove(this,event);"
onmouseup="select_mouseUp(this,event);"
>
<option value='1'>1</option>
<option value='2'>2</option>
<option value='3'>3</option>
<option value='4'>4</option>
<option value='5'>5</option>
<option value='6'>6</option>
<option value='7'>7</option>
</select>
-----------------------------
这里的函数是分别获得在IE和FIREFOX下当前鼠标位置的OPTION选项在数组中的位置
1-5的位置能够准确得到,因为SELECT的SIZE被设置成了5.而6,7因为需要滑块拖动的关系,得不到正确的位置.
希望有达人能告诉我错在哪里.
是模拟的把一个OPTION拖到另一个OPTION之后,onmouseup的时候selectedIndex不能获取到目标位置..所以我想用鼠标计算.