首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > JavaScript >

分享,搞定顽固的SELECT列表菜单,适时浏览的实战有关问题

2012-03-13 
分享,搞定顽固的SELECT列表菜单,适时浏览的实战问题很刁钻,有空狠下心花了N小时解决了,纪念个,共享下成果。

分享,搞定顽固的SELECT列表菜单,适时浏览的实战问题
很刁钻,有空狠下心花了N小时解决了,纪念个,共享下成果。

这是不加修饰的SELECT列表菜单

JScript code
<select size=15 id=a style="font-weight:bold;font-size:15;"><script>for(var i=0;i<50;i++)document.write("<option>数据库索引="+i);for(var i=0;i<50;i++)document.write("<option>数据库索引="+i);</script></select>标题<input id=neirong1 style="width:50%"><p>内容<textarea id=neirong2 style="width:50%;height:200"></textarea><script>a.selectedIndex=0function a.onmousemove(){neirong1.value=a[a.selectedIndex].text;neirong2.value=neirong1.value+"的数据库中的内容\n\n这是传统的,浏览不适时、流畅,只能点击,不能拖啦快速浏览较麻烦"}</script>


以下是程序解决方案

JScript code
<div id=select1 style="height:60%;overflow-y:scroll;padding:0;margin-left:200;"><select style="font-weight:bold;font-size:15;"><script>for(var i=0;i<50;i++)document.write("<option>数据库索引="+i);for(var i=0;i<50;i++)document.write("<option>数据库索引="+i)</script></select></div>标题<input id=neirong1 style="width:50%"><input type=button value="随机字号" onclick="select1.children[0].style.fontSize=5+Math.round(Math.random()*30);superselect(select1)"><p>内容<textarea id=neirong2 style="width:50%;height:200"></textarea><script>function superselect(fromobj){   //这套函数套用时,直接把fromobj项绑定为需要适时浏览的SELECT对象ID,可以任意绑定多个,互不影响。var a=fromobj.children[0],thelen=a.options.length;a.selectedIndex=0;a.size=thelen;fromobj.style.width=a.offsetWidthvar onesize=(a.offsetHeight-6)/thelena.onkeydown=function(){return false;}  //键盘排除,本例暂不编制上下键的程序a.onmousedown=function(){if(event.button==1)a.ckin=true;}a.onmouseup=function(){fromobj.onmousemove();if(event.button==1)a.ckin=false;fromobj.focus();}fromobj.onmousemove=function(){if(!a.ckin)return;//if(event.offsetX>a.offsetWidth||event.offsetX<0)return;  注意:这句防止聚焦捕捉,可选用,你可以去掉注释试一试,排除外出错误var inthe=Math.floor(event.offsetY/onesize);if(inthe<0)inthe=0;if(inthe>=thelen)inthe=thelen-1if(event.y>fromobj.offsetTop+fromobj.offsetHeight-(fromobj.offsetHeight/5))fromobj.scrollTop+=2if(event.y<fromobj.offsetTop+(fromobj.offsetHeight/5))fromobj.scrollTop--neirong1.value=a.options[inthe].text;neirong2.value=neirong1.value+"的数据库中的内容\n\n这是哥的实现方法(思路=像素+DIV容器,ie6测试基本完美),此例实战select适时选项貌似简单,实际比较复杂,用处很大,你懂的。。。\n\n因为1:option不支持任何事件,且其selected属性必须弹起鼠标才能更新\n因为2:SELECT本身不支持scroll滚动条的一切属性和方法,所以,外围必须包附一个DIV模拟\n因为3:你试试就知道难度在哪儿了。。。除非有专用解决此题的HTML属性或事件而我却不知\n\n原作者:略,勿需署名\n\n期待:欢迎高人用更简便的方式解决此貌似简单、实际复杂的一题,实现同等效果、无漏洞,取其最简、优,备收藏留用,我会悄悄的Mark~捏哈哈"}}superselect(select1);      //更多的话,可用superselect(select2)、superselect(select3).....</script>


[解决办法]
谢谢分享
[解决办法]
看下,呵呵
[解决办法]
喜欢分享,共同进步!THANK YOU!
[解决办法]
先顶顶,有一阵子没练铁头功了
[解决办法]
谢谢,分享了

热点排行