由于系统自带的select实在是不好用,这里我用javascript写了一个全新的select.
功能:
1.可编辑的select
2.长度可以随意修改
3.可以遮盖系统select
4.支持forms
5.支持css修改外观
6.修正在ie 5.0上运行出错的问题
7.支持使用js脚本
使用方法
[b]var 实体化变量=new editselect(名字,长度,默认字符串,宽度,高度,只读)[/b]
[b]实体化变量.add(option数值,js脚本)[/b]
这只是一个测试版,很多功能没有完善,比如没有区分value和caption等等,希望大家提出宝贵意见.
function isie(){
a=navigator.appversion.split(";")
b=a[1].split(" ")
return parsefloat(b[2])
}
if (isie()<5.5)
{
schtml='<!---->selectáð表'
}
else
{
schtml='selectáð表'
}
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=''
+'
' +' |
'
+''
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='
'+combo.options[i] } vhtml+=" |
"
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'
}
}
}
.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
}
可编辑的select |
var sel1=new editselect("select1","25","可编辑的select",""); sel1.add("这是一个可以编辑的select") sel1.add("支持css") sel1.add("可以通过css,修改外形") sel1.add("突破原来的select诸多限制") |
长度可以随意修改 可以设置为只读 |
var sel2=new editselect("select2","20","长度可以随意修改",250,82,1); sel2.add("作者:舜子制作") |
可以遮盖系统select |
var sel3=new editselect("select3","25","可以遮盖系统select","",41); |
系统的select |
[ctrl+a 全选 注:如需引入外部js需刷新才能执行]