>>> 帝国网站管理系统5.1开源测试版下载
帝国CMS进入开源时代
 帝国论坛技术交流区建站交流select 组件 javascript 实现 【本版专题贴子】  
主题:select 组件 javascript 实现 [加入收藏夹]   

wm_chief
用户头衔:管理员

精华贴   :21
发贴数   :47888
经验值   :109433
注册时间:2002-10-30
信息 搜索 好友 发送悄悄话 开源第一波:帝国备份王2008开源版发布】   [第 1 楼]
select 组件 javascript 实现
来源: PHP下

<html>
<head>
    <title>Unseal</title>
    <meta http-equiv="Content-Type" content="text/html; charset=GBK"/>
    <script language="JavaScript" src="includes/js/prototype.js"></script>
<style>
    .text {
        background: #fff;
        padding-left: 5px;
        font-size: 12px;
        font-family: Verdana, Arial, Helvetica, sans-serif;
        line-height: 14px;
        background-color: #F8F8F8;
        border-top: 1px solid #303030;
        border-right: 1px solid #D2D2D2;
        border-bottom: 1px solid #D2D2D2;
        border-left: 1px solid #303030; color: #333;
    }
    .optionDiv{
        float:left;
        position: relative;
        display: inline;
        width:0px;
        height: 0px;
        cursor: default;
        margin-right:-2px;
        top: 15px;
        left: -6px;
        background:#fff;
        z-index:9999999;
    }
    .optionsDiv{
        left: 0px;
        position: absolute;
        top: 0px;
        visibility: hidden;
        border:1px solid #303030;
        border-top:0px;
    }
</style>
</head>

<body>
<table cellpadding="10" width="100%" height="300">
    <tr>
        <td width="40%" align="right"><select><option>1</option><option>1</option></select></td>
        <td width="20%">
            <div id="songlai1" style="width:150px;"></div>
        </td>
        <td width="40%"><input type="button" value="alert()" onclick="alert($F('shenme'))" /></td>
    </tr>
</table>
<script>
    var SelectTag = Class.create();;
    SelectTag.prototype = {
        it : this,
        initialize: function(cont,name,list,selected) {
            this.bodyid = cont;
            this.__name = name;
            this.__elem = null;
            this.is = selected||this.getBodyElement().getAttribute("selected");
            this.selectDiv = null;
            this.optionsDiv = null;
            this.option = list;
            this.show = false;
            this.setSelect();
            this.setOption();
        },
        createOption: function(option,value){
            var thisoption = document.createElement("div");
            thisoption = this.optionsDiv.appendChild(thisoption);
            thisoption.setAttribute("id",this.__name+"_optionid_"+value);
            thisoption.style.backgroundColor = "#ffffff";
            thisoption.style.border  = "1px dotted #ffffff";
            thisoption.innerHTML = option;
            thisoption.name = option;
            thisoption.value = value;
            thisoption.setAttribute("it",this);
            thisoption.onmouseover = function(){
                var thisselected = $(this.it.__name+"_optionid_"+$F(this.it.__name));
                thisselected.style.backgroundColor = "#ffffff";
                thisselected.style.borderStyle = "dotted";
                thisselected.style.borderColor = "#ffffff";
                this.style.backgroundColor = "#B2B4BF";
                this.style.borderStyle = "dashed";
                this.style.borderColor = "#D4D2D9";
            }
            thisoption.onmouseout = function(){
                this.style.backgroundColor = "#ffffff";
                this.style.borderStyle = "dotted";
                this.style.borderColor = "#ffffff";
            }
            thisoption.onclick = function(){
                this.it.selectDiv.innerHTML = this.name;
                this.it.valueInp.value = this.value;
            }
        },
        setOption: function(){
            this.createOption("请选择...","");
            for(var key in this.option){
                if(typeof(eval("this.option."+key)) != 'function'){
                    this.createOption(eval("this.option."+key),key);
                }
            }
        },
        setSelect: function(){
            //select 主体
            var bodyid = this.getBodyElement();
            bodyid.className = "text";
            bodyid.style.cursor = "pointer";
            bodyid.setAttribute("it",this);
            //bodyid.attachEvent("onclick",this.showHideDiv);
            //创建选项 div
            var optionDiv = document.createElement("div");
            optionDiv = bodyid.appendChild(optionDiv);
            optionDiv.className = "optionDiv";
                var optionsDiv = document.createElement("div");
                this.optionsDiv = optionsDiv;
                optionsDiv = optionDiv.appendChild(optionsDiv);
                optionsDiv.className = "optionsDiv";
                optionsDiv.style.width = bodyid.offsetWidth+"px";
                optionsDiv.style.height = bodyid.offsetHeight+"px";
            //打开下拉箭头
            var tree = document.createElement("div");
            tree = bodyid.appendChild(tree);
            tree.style.styleFloat = "right";
            tree.style.background = "#ccc";
            tree.style.borderLeft  = "1px solid";
            this.tree = tree;
            tree.innerHTML = "∵";
            //创建显示属性 div
            var selectDiv = document.createElement("div");
            selectDiv = bodyid.appendChild(selectDiv);
            this.selectDiv = selectDiv;
            selectDiv.innerHTML = eval("this.option."+this.is)||"请选择...";
            //创建 value
            var valueInp = document.createElement("input");
            valueInp.setAttribute("type","hidden");
            valueInp.setAttribute("name",this.__name);
            valueInp.setAttribute("id",this.__name);
            valueInp.setAttribute("value",this.is||"");
            valueInp = bodyid.appendChild(valueInp);
            this.valueInp = valueInp;
            bodyid.onclick = function(){
                window.event.cancelBubble = true;
                if(this.it.show){
                    document.body.onclick = function(){try{delete window.test;}catch(e){}};
                    var thisselected = $(this.it.__name+"_optionid_"+$F(this.it.__name));
                    thisselected.style.backgroundColor = "#ffffff";
                    thisselected.style.borderStyle = "dotted";
                    thisselected.style.borderColor = "#ffffff";
                    this.it.optionsDiv.style.visibility = "hidden";
                    this.it.show = false;
                }else{
                    document.body.onclick = function(){window.test.onclick();}
                    var thisselected = $(this.it.__name+"_optionid_"+$F(this.it.__name));
                    thisselected.style.backgroundColor = "#B2B4BF";
                    thisselected.style.borderStyle = "dashed";
                    thisselected.style.borderColor = "#D4D2D9";
                    this.it.optionsDiv.style.visibility = "visible";
                    this.it.show = true;
                    window.test = this.it.getBodyElement();
                }
            }
            /*bodyid.onblur = function(){
                if(this.it.show){
                    this.it.optionsDiv.style.visibility = "hidden";
                    this.it.show = false;
                }
            }*/
        },
        getBodyElement: function () {
            if ( ! this.__elem ) {
                if ( typeof(this.bodyid) == "object" && this.bodyid.parentNode ) {
                    this.__elem = this.bodyid;
                    this.bodyid = this.__elem.id;
                } else {
                    this.__elem = $( this.bodyid );
                }
            }
            return this.__elem;
        }
    }
    var ss = new SelectTag("songlai1","shenme1",{a:'a',b:'b',c:'c',d:'d'},'c');
</script>
</body>
</html>



[零基础入门教程] [模板制作教程] [采集使用教程]
2005-11-25 02:15:56 已设置保密 顶部 回复 引用 报告 编辑 删除

vip
用户头衔:举人 *

精华贴   :0
发贴数   :327
经验值   :1202
注册时间:2005-03-11
信息 搜索 好友 发送悄悄话 《帝国网站管理系统》零基础实例入门教程】   [第 2 楼]

好东东~~




2005-11-24 13:34:12 已设置保密 顶部 回复 引用 报告 编辑 删除

快速回复
内容

表情
使用EBB代码 使用smile代码 显示签名 自动分析url 自动分析img
     【进入高级模式】   (按 Ctrl+Enter 直接提交)
    顶部  加入收藏夹
关于帝国 | 广告服务 | 联系我们 | 法律声明 | 隐私条款 | 许可协议
Powered by: EBB Version 2.2.1