js下用层来实现select的title提示属性


Posted in Javascript onFebruary 23, 2010
<script> 
             function opts(selectObj){ 
                         var optDivs=document.createElement("div"); 
                         var objTable=document.createElement("table"); 
                         var objTbody=document.createElement("tbody"); 
                         optDivs.style.zIndex = "100"; 
                         objTable.style.zIndex = "100"; 
                         objTable.width=selectObj.style.width;     
                         objTable.border = "0"; 
                         objTable.cellPadding = "0"; 
                         objTable.cellSpacing = "0"; 
                         objTable.style.paddingLeft = "2";     
                         objTable.style.fontFamily = "Verdana, Arial, Helvetica, sans-serif";                          var e = selectObj; 
                         var absTop = e.offsetTop; 
                         var absLeft = e.offsetLeft; 
                         var absWidth = e.offsetWidth; 
                         var absHeight = e.offsetHeight; 
                         while(e = e.offsetParent){ 
                         absTop += (e.offsetTop+0.3); 
                         absLeft += e.offsetLeft; 
                         } 
                         with (objTable.style){ 
                         position = "absolute"; 
                         top = (absTop + absHeight) + "px"; 
                         left = (absLeft+1) + "px"; 
                         border = "1px solid black"; 
                         tableLayout="fixed"; 
                         wordBreak="break-all"; 
                         } 
                         var options = selectObj.options; 
                         var val=selectObj.value; 
                            if (options.length > 0){ 
                                 for (var i = 0; i < options.length; i++){ 
                                     var newOptDiv = document.createElement("td"); 
                                     var objRow=document.createElement("tr"); 
                             newOptDiv.name=options[i].value; 
                             newOptDiv.innerText=options[i].innerText; 
                             newOptDiv.title=options[i].title; 
                             newOptDiv.onmouseout = function() {this.className='smouseOut';val=selectObj.value}; 
                             newOptDiv.onmouseover = function() {this.className='smouseOver';val=this.name;}; 
                             newOptDiv.className="smouseOut"; 
                             newOptDiv.style.width=40; 
                             newOptDiv.style.cursor="default"; 
                             newOptDiv.style.fontSize = "11px"; 
                             newOptDiv.style.fontFamily = "Verdana, Arial, Helvetica, sans-serif"; 
                             objRow.appendChild(newOptDiv); 
                             objTbody.appendChild(objRow); 
                             } 
                            } 
                     
                            objTbody.appendChild(objRow); 
                            objTable.appendChild(objTbody); 
                            optDivs.appendChild(objTable); 
                            document.body.appendChild(optDivs); 
                             var IfrRef = document.createElement("div"); 
                            IfrRef.style.position="absolute"; 
                            IfrRef.style.width = objTable.offsetWidth; 
                            IfrRef.style.height = objTable.offsetHeight; 
                            IfrRef.style.top = objTable.style.top; 
                            IfrRef.style.left = objTable.style.left; 
                            IfrRef.style.backgroundColor = document.bgColor; 
                            document.body.appendChild(IfrRef); 
                            objTable.focus(); 
                            objTable.onblur=function() {choose(selectObj,val,optDivs,IfrRef)}; 
         } 
         function choose(objselect,val,delobj,delobj2){ 
             objselect.value=val; 
             document.body.removeChild(delobj); 
             document.body.removeChild(delobj2); 
         } 
         </script> 
         
         <STYLE> 
                    .smouseOut { 
                            background: document.bgColor; 
                            color: #000000; 
                    } 
                    .smouseOver { 
                            background: rgb(0,128,128); 
                            color: #FFFFFF; 
                            cursor: pointer; 
                    } 
            </style> 
         
         <select id='selId'    style='width:50px' class='black' onclick="opts(this);"> 
                <option value='1' title="One....">111</option> 
                <option value='2' title="Two....">222</option> 
            </select>
Javascript 相关文章推荐
CSS中position属性之fixed实现div居中
Dec 14 Javascript
Node.js 应用跑得更快 10 个技巧
Apr 03 Javascript
AngularJS控制器继承自另一控制器
May 09 Javascript
Node.js中process模块常用的属性和方法
Dec 13 Javascript
vue-router路由简单案例介绍
Feb 21 Javascript
JavaScript组件开发之输入框加候选框
Mar 10 Javascript
Node.js中的http请求客户端示例(request client)
May 04 Javascript
使用 Vue.js 仿百度搜索框的实例代码
May 09 Javascript
详解vue服务端渲染(SSR)初探
Jun 19 Javascript
javascript浏览器用户代理检测脚本实现方法
Oct 27 Javascript
利用CDN加速react webpack打包后的文件详解
Feb 22 Javascript
如何在VUE中使用vue-awesome-swiper
Jan 04 Vue.js
jquery 锁定弹出层实现代码
Feb 23 #Javascript
javascript document.compatMode兼容性
Feb 23 #Javascript
js操作ajax返回的json的注意问题!
Feb 23 #Javascript
javascript入门基础之私有变量
Feb 23 #Javascript
第一个JavaScript入门基础 document.write输出
Feb 22 #Javascript
jQuery入门问答 整理的几个常见的初学者问题
Feb 22 #Javascript
jQuery 操作下拉列表框实现代码
Feb 22 #Javascript
You might like
PHP程序守护进程化实现方法详解
2020/07/16 PHP
javascript firefox兼容ie的dom方法脚本
2008/05/18 Javascript
js性能优化 如何更快速加载你的JavaScript页面
2012/03/17 Javascript
详解jquery uploadify 上传文件
2013/11/09 Javascript
Ajax清除浏览器js、css、图片缓存的方法
2015/08/06 Javascript
jQuery使用serialize()表单序列化时出现中文乱码问题的解决办法
2016/07/27 Javascript
很酷的星级评分系统原生JS实现
2016/08/25 Javascript
BootStrap fileinput.js文件上传组件实例代码
2017/02/20 Javascript
利用js的闭包原理做对象封装及调用方法
2017/04/07 Javascript
Centos6.8下Node.js安装教程
2017/05/12 Javascript
bootstrap table插件的分页与checkbox使用详解
2017/07/23 Javascript
关于Ajax的原理以及代码封装详解
2017/09/08 Javascript
利用JS hash制作单页Web应用的方法详解
2017/10/10 Javascript
详解微信小程序框架wepy踩坑记录(与vue对比)
2019/03/12 Javascript
JavaScript中var的重要性实例分析
2019/07/09 Javascript
关于ckeditor在bootstrap中modal中弹框无法输入的解决方法
2019/09/11 Javascript
[03:02]安得倚天剑,跨海斩长鲸——中国军团出征DOTA2国际邀请赛
2018/08/14 DOTA
Python编程之变量赋值操作实例分析
2017/07/24 Python
python分布式环境下的限流器的示例
2017/10/26 Python
Python探索之静态方法和类方法的区别详解
2017/10/27 Python
python 平衡二叉树实现代码示例
2018/07/07 Python
正确理解Python中if __name__ == '__main__'
2019/01/24 Python
使用Pycharm在运行过程中,查看每个变量的操作(show variables)
2020/06/08 Python
解决运行出现'dict' object has no attribute 'has_key'问题
2020/07/15 Python
Python读取yaml文件的详细教程
2020/07/21 Python
如何在python中判断变量的类型
2020/07/29 Python
澳大利亚快时尚鞋类市场:Billini
2018/05/20 全球购物
村党支部对照检查材料思想汇报
2014/09/28 职场文书
单位介绍信格式
2015/01/31 职场文书
建筑质检员岗位职责
2015/04/08 职场文书
鸡毛信观后感
2015/06/11 职场文书
三好学生主要事迹怎么写
2015/11/03 职场文书
2016年感恩教师节活动总结
2016/04/01 职场文书
数据库之SQL技巧整理案例
2021/07/07 SQL Server
SQL Server中锁的用法
2022/05/20 SQL Server
SQL解决未能删除约束问题drop constraint
2022/05/30 SQL Server