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 相关文章推荐
3Z版基于jquery的图片复选框(asp.net+jquery)
Apr 12 Javascript
解读JavaScript中 For, While与递归的用法
May 07 Javascript
js单例模式的两种方案
Oct 22 Javascript
jquery改变disabled的boolean状态的三种方法
Dec 13 Javascript
微信分享的标题、缩略图、连接及描述设置方法
Oct 14 Javascript
基于jQuery实现仿淘宝套餐选择插件
Mar 04 Javascript
Javascript 字符串模板的简单实现
Feb 13 Javascript
JS常用的几种数组遍历方式以及性能分析对比实例详解
Apr 11 Javascript
简单了解vue.js数组的常用操作
Jun 17 Javascript
vue路由拦截器和请求拦截器知识点总结
Nov 08 Javascript
Vue-CLI 3 scp2自动部署项目至服务器的方法
Jul 24 Javascript
Javascript实现贪吃蛇小游戏(含详细注释)
Oct 23 Javascript
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
咖啡知识 咖啡养豆要养多久 排气又是什么
2021/03/06 新手入门
php array_flip() 删除数组重复元素
2009/01/14 PHP
php获取参数的几种方法总结
2014/02/18 PHP
Laravel 5.3 学习笔记之 错误&amp;日志
2016/08/28 PHP
PHP简单实现循环链表功能示例
2017/11/10 PHP
JavaScript获取GridView中用户点击控件的行号,列号
2009/04/14 Javascript
javascript操作cookie的文章(设置,删除cookies)
2010/04/01 Javascript
mysql输出数据赋给js变量报unterminated string literal错误原因
2010/05/22 Javascript
JavaScript中的变量定义与储存介绍
2014/12/31 Javascript
node.js操作mongodb学习小结
2015/04/25 Javascript
JQuery中上下文选择器实现方法
2015/05/18 Javascript
jQuery如何使用自动触发事件trigger
2015/11/29 Javascript
jQuery仿京东商城楼梯式导航定位菜单
2016/07/25 Javascript
Vue.js原理分析之observer模块详解
2017/02/17 Javascript
javascript标准库(js的标准内置对象)总结
2018/05/26 Javascript
实例详解vue中的$root和$parent
2019/04/29 Javascript
中级前端工程师必须要掌握的27个JavaScript 技巧(干货总结)
2019/09/23 Javascript
JS原形与原型链深入详解
2020/05/09 Javascript
JavaScript闭包原理与用法学习笔记
2020/05/29 Javascript
python处理PHP数组文本文件实例
2014/09/18 Python
windows下python安装paramiko模块和pycrypto模块(简单三步)
2017/07/06 Python
Python中的几种矩阵乘法(小结)
2019/07/10 Python
使用Filter过滤python中的日志输出的实现方法
2019/07/17 Python
python Pillow图像处理方法汇总
2019/10/16 Python
用pytorch的nn.Module构造简单全链接层实例
2020/01/14 Python
django使用graphql的实例
2020/09/02 Python
AmazeUI 评论列表的实现示例
2020/08/13 HTML / CSS
万豪国际住宅与别墅集团:Homes & Villas by Marriott International
2020/10/08 全球购物
C#中有没有运算符重载?能否使用指针?
2014/05/05 面试题
2014年母亲节寄语
2014/05/07 职场文书
2014年党课学习材料
2014/05/11 职场文书
2014年世界艾滋病日宣传活动总结
2014/11/18 职场文书
背起爸爸上学观后感
2015/06/08 职场文书
医院中层管理人员培训心得体会
2016/01/11 职场文书
Pytorch 使用tensor特定条件判断索引
2021/04/08 Python
Go语言grpc和protobuf
2022/04/13 Golang