zhao
2021-07-19 8347f2fbddbd25369359dcb2da1233ac48a19fdc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
/*#############################################################
Name: Select to CSS
Version: 0.2
Author: Utom
URL: http://utombox.com/
#############################################################*/
var selects = document.getElementsByTagName('select');
 
var isIE = (document.all && window.ActiveXObject && !window.opera) ? true : false;
 
function GetID(id) {
    return document.getElementById(id);
}
 
function stopBubbling (ev) {    
    ev.stopPropagation();
}
 
function rSelects() {
    for (i=0;i<selects.length;i++){
        selects[i].style.display = 'none';
        select_tag = document.createElement('div');
            select_tag.id = 'select_' + selects[i].name;
            select_tag.className = 'select_box';
        selects[i].parentNode.insertBefore(select_tag,selects[i]);
 
        select_info = document.createElement('div');    
            select_info.id = 'select_info_' + selects[i].name;
            select_info.className='tag_select';
            select_info.style.cursor='pointer';
        select_tag.appendChild(select_info);
 
        select_ul = document.createElement('ul');    
            select_ul.id = 'options_' + selects[i].name;
            select_ul.className = 'tag_options';
            select_ul.style.position='absolute';
            select_ul.style.display='none';
            select_ul.style.zIndex='999';
        select_tag.appendChild(select_ul);
 
        rOptions(i,selects[i].name);
        
        mouseSelects(selects[i].name);
 
        if (isIE){
            selects[i].onclick = new Function("clickLabels3('"+selects[i].name+"');window.event.cancelBubble = true;");
        }
        else if(!isIE){
            selects[i].onclick = new Function("clickLabels3('"+selects[i].name+"')");
            selects[i].addEventListener("click", stopBubbling, false);
        }        
    }
}
 
 
function rOptions(i, name) {
    var options = selects[i].getElementsByTagName('option');
    var options_ul = 'options_' + name;
    for (n=0;n<selects[i].options.length;n++){    
        option_li = document.createElement('li');
            option_li.style.cursor='pointer';
            option_li.className='open';
        GetID(options_ul).appendChild(option_li);
 
        option_text = document.createTextNode(selects[i].options[n].text);
        option_li.appendChild(option_text);
 
        option_selected = selects[i].options[n].selected;
 
        if(option_selected){
            option_li.className='open_selected';
            option_li.id='selected_' + name;
            GetID('select_info_' + name).appendChild(document.createTextNode(option_li.innerHTML));
        }
        
        option_li.onmouseover = function(){    this.className='open_hover';}
        option_li.onmouseout = function(){
            if(this.id=='selected_' + name){
                this.className='open_selected';
            }
            else {
                this.className='open';
            }
        } 
    
        option_li.onclick = new Function("clickOptions("+i+","+n+",'"+selects[i].name+"')");
    }
}
 
function mouseSelects(name){
    var sincn = 'select_info_' + name;
 
    GetID(sincn).onmouseover = function(){ if(this.className=='tag_select') this.className='tag_select_hover'; }
    GetID(sincn).onmouseout = function(){ if(this.className=='tag_select_hover') this.className='tag_select'; }
 
    if (isIE){
        GetID(sincn).onclick = new Function("clickSelects('"+name+"');window.event.cancelBubble = true;");
    }
    else if(!isIE){
        GetID(sincn).onclick = new Function("clickSelects('"+name+"');");
        GetID('select_info_' +name).addEventListener("click", stopBubbling, false);
    }
 
}
 
function clickSelects(name){
    var sincn = 'select_info_' + name;
    var sinul = 'options_' + name;    
 
    for (i=0;i<selects.length;i++){    
        if(selects[i].name == name){                
            if( GetID(sincn).className =='tag_select_hover'){
                GetID(sincn).className ='tag_select_open';
                GetID(sinul).style.display = '';
            }
            else if( GetID(sincn).className =='tag_select_open'){
                GetID(sincn).className = 'tag_select_hover';
                GetID(sinul).style.display = 'none';
            }
        }
        else{
            GetID('select_info_' + selects[i].name).className = 'tag_select';
            GetID('options_' + selects[i].name).style.display = 'none';
        }
    }
 
}
 
function clickOptions(i, n, name){        
    var li = GetID('options_' + name).getElementsByTagName('li');
 
    GetID('selected_' + name).className='open';
    GetID('selected_' + name).id='';
    li[n].id='selected_' + name;
    li[n].className='open_hover';
    GetID('select_' + name).removeChild(GetID('select_info_' + name));
 
    select_info = document.createElement('div');
        select_info.id = 'select_info_' + name;
        select_info.className='tag_select';
        select_info.style.cursor='pointer';
    GetID('options_' + name).parentNode.insertBefore(select_info,GetID('options_' + name));
 
    mouseSelects(name);
 
    GetID('select_info_' + name).appendChild(document.createTextNode(li[n].innerHTML));
    GetID( 'options_' + name ).style.display = 'none' ;
    GetID( 'select_info_' + name ).className = 'tag_select';
    selects[i].options[n].selected = 'selected';
 
}
 
window.onload = function(e) {
    bodyclick = document.getElementsByTagName('body').item(0);
    rSelects();
    bodyclick.onclick = function(){
        for (i=0;i<selects.length;i++){    
            GetID('select_info_' + selects[i].name).className = 'tag_select';
            GetID('options_' + selects[i].name).style.display = 'none';
        }
    }
}