可编辑select

<html> 

<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>EditSelect</title>
<script>
function isIE(){
a=navigator.appVersion.split(";")
b=a[1].split(" ")
return parseFloat(b[2])
} 

if (isIE()<5.5)
{
     scHTML=‘<div id="selectcontent" class="selectdiv" style="visibility:hidden;"><!--<iframe id=selframe frameborder=0 height=100%></iframe>--><div id="selecthtml" class="selectcontent">selectÁÐ表</div></div>‘
}
else
{
     scHTML=‘<div id="selectcontent" class="selectdiv" style="visibility:hidden;"><iframe id=selframe frameborder=0 height=100%></iframe><div id="selecthtml" class="selectcontent">selectÁÐ表</div></div>‘
} 

document.write(scHTML)
vDiv=selectcontent
vDivHtml=selecthtml 

function editselect(name,size,defaulttext,width,height,readonly){
  var combo=this;
  this.options=new Array();
  this.oj=new Array();
  this.name=name;
  this.divname=name+‘_div‘;
  this.buttonname=name+‘_button‘;
  this.tablename=name+‘_table‘;
  this.htmltable=name+‘_html‘
  if (!height) this.height=0; else this.height=height
  if (width) this.width=width
  if (!size) size=8
  if (!defaulttext) defaulttext=""
  if (!readonly || readonly==0) {readonly="" }else {if (readonly==1) readonly="readonly style=cursor:default";this.readonly=1} 

  esHTML=‘<div id=‘+this.divname+‘>‘
         +‘<table id=‘+this.tablename+‘ cellpadding=0 cellspacing=0 class=select><tr><td bgcolor=#FFFFFF>‘
         +‘<input type=text class=selecttext size="‘+size+‘" name=‘+name+‘ value="‘+defaulttext+‘" ‘+readonly+‘><td><button class=selectbutton id=‘+this.buttonname+‘>6</td></tr></table>‘
         +‘</div>‘
  document.write(esHTML)
  this.sbutton=eval("document.all."+this.buttonname) 

  if (this.readonly==1) eval("document.all."+this.name).onclick=function(){combo.show()}   

  this.sbutton.onclick=function(){combo.show()}
  this.show=function(){
    pDiv=eval(combo.divname)
    pTable=eval(combo.tablename)
    var vHTML=‘<table id=htmltable cellspacing="0" cellpadding="2" bgcolor="#ffffff" class="selecttable" width=100%>‘
    for (i=0;i<combo.options.length;i++)
      {
       vHTML+=‘<tr onmouseover="mo(this)" onmouseout="mu(this)" onclick="document.all.‘+combo.name+‘.value=this.innerText;selectcontent.style.visibility=\‘hidden\‘;‘+combo.oj[i]+‘"><td nowrap>‘+combo.options[i]
      }
     vHTML+="</table>"
    vDivHtml.innerHTML=vHTML 

    vtop=pDiv.offsetTop+pDiv.offsetHeight
    vleft=pDiv.offsetLeft+2 

    vParent = pDiv.offsetParent;
     while (vParent.tagName.toUpperCase() != "BODY")
 {
  vleft += vParent.offsetLeft;
  vtop += vParent.offsetTop;
  vParent = vParent.offsetParent;
 } 

   var redge=document.body.clientWidth-vleft
   var bedge=document.body.clientHeight-vtop 

 if (!combo.width) {vDiv.style.width=pTable.offsetWidth} else {vDiv.style.width=combo.width} 

    if (combo.height==0)
      {
        vDiv.style.pixelHeight=parseInt(htmltable.offsetHeight)+2
        vDivHtml.style.pixelHeight=parseInt(htmltable.offsetHeight)+2
      }
      else
      {
         if (htmltable.offsetHeight>combo.height)
          {
            vDiv.style.pixelHeight=combo.height
            vDivHtml.style.pixelHeight=combo.height 

            }
           else
           { 

              vDiv.style.pixelHeight=parseInt(htmltable.offsetHeight)+2
              vDivHtml.style.pixelHeight=parseInt(htmltable.offsetHeight)+2
           } 

       } 

    vDivHtml.scrollTop=0 

    if (redge<vDiv.offsetWidth)
      vDiv.style.left=vleft-1-(vDiv.offsetWidth-redge)
        else
      vDiv.style.left=vleft-1 

   if (bedge<vDiv.offsetHeight)
    //vDiv.style.top=vtop-vDiv.offsetHeight-pDiv.offsetHeight
    vDiv.style.top=vtop-vDiv.offsetHeight+bedge
         else
      vDiv.style.top=vtop 

    vDivHtml.style.width=parseInt(vDiv.style.width)
      vDiv.style.visibility="visible"
  } 

  this.add=function(text,js){
     combo.options[combo.options.length]=text
     combo.oj[combo.oj.length]=js 

  } 

  this.clearall=function(){
  combo.options=new Array()
  } 

  this.about=function(){ 

 }
} 

function mo(obj){
obj.style.backgroundColor="#000099"
obj.style.color="#ffffff"
} 

function mu(obj){
obj.style.backgroundColor=""
obj.style.color="#000000"
} 

document.onmousedown=function(){
if (vDiv.style.visibility=="visible"){
mx=event.x + document.body.scrollLeft
my=event.y + document.body.scrollTop; 

x1=vDiv.offsetLeft
y1=vDiv.offsetTop 

x2=vDiv.offsetLeft+vDiv.offsetWidth
y2=vDiv.offsetTop+vDiv.offsetHeight 

if (mx<x1 || my<y1 || x2<mx || y2<my)
   {
     vDiv.style.visibility=‘hidden‘
   }
}
}</script> 

<style>
.selecttext{
border:0px
height: 16;
font-family:arial;
font-size:12px;
}
.selectbutton{
font-family:webdings;
font-size:10px;
height: 19;
width: 16;
border:1px solid #83A5EB;
line-height:0px;
padding-bottom:3px;
background-color:#D1E0FD
}
.selecttable{
font-family:arial;
font-size:12px;
cursor:default;
}
.selectcontent
{
position: absolute;
top:0;
left:0;
overflow:auto;
border:1px solid #000000
} 

.selectdiv
{
position: absolute;
width:100;
overflow:hidden;
}
.select{
border-collapse: collapse;
border:1px solid #7F9DB9
}
</style>
</head> 

<body bgcolor="#83A5EB"> 

<table border="0" width="100%">
    <tr>
        <td width="151" align="center"><font size="2">可编辑的Select</font></td>
        <td><script>
var sel1=new editselect("select1","25","可编辑的Select","");
sel1.add("这是一个可以编辑的Select")
sel1.add("支持CSS")
sel1.add("可以通过CSS,修改外形")
sel1.add("突破原来的Select诸多限制")
</script></td>
    </tr>
    <tr>
        <td width="151" align="center"><font size="2">长度可以随意修改
可以设置为只读</font></td>
        <td>
        <script>
var sel2=new editselect("select2","20","长度可以随意修改",250,82,1);
sel2.add("这是一个可以编辑的Select")
sel2.add("支持CSS")
sel2.add("可以通过CSS,修改外形") 

sel2.add("作者:舜子制作")
sel2.add("MSN:[email protected]")
</script>
        </td>
    </tr>
    <tr>
        <td width="151" align="center"><font size="2">可以遮盖系统Select</font></td>
        <td>
        <script>
var sel3=new editselect("select3","25","可以遮盖系统Select","",41);
sel3.add("这是一个可以编辑的Select")
sel3.add("支持CSS")
sel3.add("可以通过CSS,修改外形")
sel3.add("突破原来的Select诸多限制")
</script>
        </td>
    </tr>
    <tr>
        <td width="151" align="right"> </td>
        <td><select><option>系统的Select</option></select> </td>
    </tr>
</table>
</body> 

</html> 

http://www.jb51.net/article/914.htm

时间: 2024-08-25 09:47:50

可编辑select的相关文章

可编辑的select框的实现(实用版)

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">< HTML> < HEAD>  < TITLE>可编辑select</TITLE>   < script>     function selShiftDesc(desc){    if(desc.options.selectedIndex!=0){    var v=desc.value; 

jquery实现可编辑的下拉框( input + select )

HTML: <input id="inputModel" /> <select name="EngineModel" size="10" style="height: auto; margin-left: 120px; position: absolute; display: none;"></select> Jquery: //获取select var engine = $('select

jqgrid 实现行编辑,表单编辑的列联动

这个问题的场景相信大家都遇到过,比如有A,B,C三列,B,C列均为下拉框,但是C列的值是由B列的值来决定的,即C列中的值是动态变化的,变化的依据就是B列中你选择的值.本文给出的是一个实用,简易快捷的实现方式.先看图: 本例子实现的如果是常白班,则班别那一列只显示白班,否则的话,那就显示白晚班.可以看成是两列联动. 实现核心代码为: onSelectRow: function (id) { if (id && id !== lastSel) { jQuery("#TblClassT

EasyUI combobox 与 numberbox 属性不可编辑与设置值的使用

今天工作中EasyUI 页面用到的知识点,总结一下: 如下图: 需求: 设置考核价为不可编辑状态,包括考核价的交易币种符号合考核价的金额 考核价的币种和金额从合同价和考核费率数据中获取 考核价的币种同合同价币种一样,考核价金额=合同价金额*考核费率 通过设置disabled属性为true设置考核价币种下拉列表 和  考核价金额文本框 为不可编辑状态 设置考核价币种下拉列表不可编辑: <select id="asseCurrencyID" name="asseCurren

avascript小技巧

avascript小技巧 事件源对象 event.srcElement.tagName event.srcElement.type 捕获释放 event.srcElement.setCapture(); event.srcElement.releaseCapture(); 事件按键 event.keyCode event.shiftKey event.altKey event.ctrlKey 事件返回值 event.returnValue 鼠标位置 event.x event.y 窗体活动元素 

JS技术大全

事件源对象:event.srcElement.tagName  event.srcElement.type 捕获/释放:event.srcElement.setCapture();  event.srcElement.releaseCapture();  事件按键:event.keyCode, event.shiftKey, event.altKey, event.ctrlKey 事件返回值:event.returnValue 鼠标位置:event.x ,event.y 窗体活动元素:docum

JS详解

事件源对象:event.srcElement.tagName  event.srcElement.type 捕获/释放:event.srcElement.setCapture();  event.srcElement.releaseCapture();  事件按键:event.keyCode, event.shiftKey, event.altKey, event.ctrlKey 事件返回值:event.returnValue 鼠标位置:event.x ,event.y 窗体活动元素:docum

常用js特效

事件源对象  event.srcElement.tagName event.srcElement.type 捕获释放  event.srcElement.setCapture();  event.srcElement.releaseCapture(); 事件按键  event.keyCode event.shiftKey event.altKey event.ctrlKey 事件返回值  event.returnValue 鼠标位置 event.x event.y 窗体活动元素  documen

JS代码大全 (都是网上看到 自己整理的)

原文 JS代码大全 (都是网上看到 自己整理的) 事件源对象 event.srcElement.tagName  event.srcElement.type 捕获释放 event.srcElement.setCapture();   event.srcElement.releaseCapture(); 事件按键 event.keyCode  event.shiftKey  event.altKey  event.ctrlKey 事件返回值 event.returnValue 鼠标位置 event