js下用层来实现select的title提示属性_表单特效

复制代码 代码如下:

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

时间: 2024-09-20 01:03:59

js下用层来实现select的title提示属性_表单特效的相关文章

js 获取当前select元素值的代码_表单特效

1.如果 select 元素下的所有 option 元素均没有指定 selected 属性,会默认选中第一个. 2.可以通过 select.selectedIndex 获取到选中的 option 元素的索引. 3.可以通过 select.options[select.selectedIndex] 获取到选中的 option 元素. 4.option 元素 <option selected="selected" value="value3">text3&l

js限制文本框为整数和货币的函数代码_表单特效

限制为整数 <html> <head> <script language="javascript" type="text/javascript"> var G=document.getElementById; function checkNumber(){ var reg = /^(?:0|[1-9][0-9]?|100)$/; var strNumber = G("txtNumber").value; ale

js在不刷新的情况下动态添加表格行[脚本之家强烈推荐]_表单特效

添加产品品种数: 产品编号 产品名称 数量 单价

Div Select挡住的解决办法_表单特效

<html><head>     <meta http-equiv="Content-Type" content="text/html; charset=gb2312">     <title>Div下拉菜单被Select挡住的解决办法</title> </head><body> <div style="z-index: 10; position: absolute;

用javascript实现select的美化的方法_表单特效

用javascript模拟select达到美化效果 用户注册 帐号 密码 省份 江西福建广东浙江 作者博客

js onpropertychange输入框 事件获取属性_表单特效

当一个HTML元素的属性改变的时候,都能通过onpropertychange来捕获.例如< input name="text1" id="text1" />对象的value属性被页面的脚本修改的时候,onchange无法捕获到,而onpropertychange却能够捕获. 具体理解为:onpropertychange能及时捕获属性值的变化,而onchange在属性值改变时只有通过鼠标执行某些操作才能激活该事件! 但onpropertychange只有I

javascript 获取select下拉列表值的代码_表单特效

比如,在使用DWR的时候,如果你想传递下拉框的参数到后台的话,此时就需要先获取到下拉框的值了. 其实想要获取到下拉框的值是很简单的. 最关键的一段代码就是: 复制代码 代码如下: onchange="show(this.options[this.options.selectedIndex].value);" onchange="show(this.options[this.options.selectedIndex].value);" show是一个自定义的函数名.

js动态在form上插入enctype=multipart/form-data的问题_表单特效

我们都知道要让form能提交文件,需要在form上指定enctype=multipart/form-data的attribute,这样才能上传文件,关于enctype的文章很多,就不再做解释. 问题是因为使用了MVC的Html.BeginForm()来输出表单代码,默认是没有加入enctype的, 复制代码 代码如下: @using (Html.BeginForm()) { } 在PartialView中有一个<input type="file" />用来上传文件,又不想为

js checkbox全选并将获取值放到input里边_表单特效

复选1 复选2 复选3 复选4 请把复选1.复选2.复选3.复选4的值传到下面文本框中,中间以","分隔.