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

javascript 帮忙 可编辑的下拉框,该如何解决

2012-03-15 
javascript 帮忙 可编辑的下拉框scriptlanguage javascript //动态创建下拉列表functionCreateSelect

javascript 帮忙 可编辑的下拉框
<script   language= "javascript ">
  //动态创建下拉列表
function   CreateSelect(_controlSelectName,_inpubObjName)
{
}
function   combox(_inpuObjName,_controlSelectName)
{
        //生成的输入框对象名称
        this.inpuObjName=_inpuObjName;
  //生成的输入框对象
  this.inputbox=null;
        //原来的下拉框对象
        this.controlSelect=document.getElementById(_controlSelectName);
 
        //初始化对象
  //_comboxObj:combox对象,须指向自己
        this.init=function(_comboxObj)
        {
    this.inputbox=document.createElement( "input ");
    this.inputbox.id=this.inpuObjName;
    this.inputbox.comboxObj=_comboxObj;
    this.inputbox.onchange=function()
    {
      this.comboxObj.find();
    }
    with(this.inputbox.style)
    {
      width=this.controlSelect.offsetWidth-16;
      height=this.controlSelect.offsetHeight;
    }    
    this.controlSelect.insertAdjacentElement( "beforeBegin ",this.inputbox);
                _span=document.createElement( "span ");
                _span.style.width=18;
                this.controlSelect.insertAdjacentElement( "beforeBegin ",_span);
                _span.appendChild(this.controlSelect);
                _container=document.createElement( "span ");
                this.inputbox.insertAdjacentElement( "beforeBegin ",_container);
                _container.appendChild(this.inputbox);
                _container.appendChild(_span);
                _container.style.width=this.inputbox.offsetWidth+18;
                _width=this.controlSelect.offsetWidth-18;
                with   (this.controlSelect.style)
                {
                        margin= "0   0   0   - "+_width;
                }
    this.controlSelect.comboxObj=_comboxObj;
                this.controlSelect.onchange=function()
    {
      this.comboxObj.change();      
    }
                this.change();
        }
        //当搜索到输入框的值时,下拉框自动定位/
        this.find=function()
        {
                with   (this.controlSelect)
                {
                        for(i=0;i <options.length;i++)
                                if(options[i].text.indexOf(this.inputbox.value)==0)


                                {
                                        selectedIndex=i;
                                        this.change();
                                        break;
                                }
                }
        }
        //定义下拉框的onchange事件
        this.change=function()
        {                
                this.inputbox.value=this.controlSelect.options[this.controlSelect.selectedIndex].text;
                with   (this.inputbox)
                {
                        select();
                        focus();
                }
        }
}
/**
  *   定位函数,获取控件绝对坐标
  */
function   getLeftPos(e)
{
        var   left=e.offsetLeft;
        while   (e=e.offsetParent)
        {
                left+=e.offsetLeft;
        }
        return   left;
}
function   getTopPos(e)
{
        var   top=e.offsetTop;
        while   (e=e.offsetParent)
        {
                top+=e.offsetTop;
        }
        return   top;
} 


</script>

我现在想做个可以编辑的下拉矿。这个代码是先有个SELECT在创建INPUT的.我现在想先有INPUT再创建SELECT选择框.我改成this.inputbox=document.createElement( "input ");后。结果那个下拉框挡住了。文本框..谁能替我参考一下。

[解决办法]
http://www.never-online.net/blog/article.asp?id=88
[解决办法]
<html>
<head>
<meta http-equiv= "Content-Type " content= "text/html; charset=?????? ">
<title> </title>
</head>
<body onload= "c_cpua.value=c_cpu.options[c_cpu.selectedIndex].value ">
<div style= "position:absolute; ">
<select name= "c_cpu " style= "position:absolute;top:30px; width: 150px; height: 20px; clip: rect(0 180 110 130) " onChange= 'c_cpua.value=this.options[this.selectedIndex].value '>
<option value= "1 "> 1 </option>
<option value= "2 " selected> 2 </option>
<option value= "3 "> 3 </option>
<option value= "4 "> 4 </option>
</select>


<input name= "c_cpua " type= "text " style= "position:absolute;top:30px; width: 149px; height: 20px ">
</div>
<input type= "button " name= "Submit " value= "GetValue " onClick= "alert(c_cpua.value) ">
</body>
</html>
[解决办法]
<html>

<head>
<meta http-equiv= "Content-Type " content= "text/html; charset=gb2312 ">
<title> 注意 </title>
</head>

<body>
强列建议慎用Combox,
请先检查是否可以用以下方案:
<hr/>
1. <br/>
文化程度:
<select onchange= "if(this.value== '其它 ') this.nextSibling.style.display= ' '; else this.nextSibling.style.display= 'none ' ">
<option value= " "> </option> <option value= "小学 "> 小学 </option> <option value= "中学 "> 中学 </option> <option value= "大学 "> 大学 </option> <option value= "其它 "> 其它 </option>
</select> <input style= "display:none ">
<hr/>
2. <br/>
<input type=radio name=etype checked onclick= "if(this.checked) { wenhuachendu1[0].disabled=false;wenhuachendu1[1].disabled=true;} "> 文化程度(常见):
<select id=wenhuachendu1 >
<option value= " "> </option> <option value= "小学 "> 小学 </option> <option value= "中学 "> 中学 </option> <option value= "大学 "> 大学 </option> <option value= "其它 "> 其它 </option>
</select>
<br>
<input type=radio name=etype onclick= "if(this.checked) { wenhuachendu1[0].disabled=true;wenhuachendu1[1].disabled=false;} " > 文化程度(特别):
<input id=wenhuachendu1 disabled >
</body>

</html>
[解决办法]
这里也有一个combox:

http://community.csdn.net/Expert/topic/5412/5412699.xml?temp=.4549066

热点排行