作者:marvellous
本文旨在大家对select和模拟select有一个全面地了解,使此项技术能发挥出更高的水平。
最初的select的确很平淡,就是一个下拉选项列表:
日久天长之后,人们对select要求高了,要修一修边幅:
要加一些链接,变成菜单:
\n';
str += '\n';
return str;
}
function createXString(matrix, id, size, onchange, css) {
var str = '
\n';
return str;
}
function stripTags(str) {
var s = 0;
var e = -1;
var r = "";
s = str.indexOf("<",e);
do {
r += str.substring(e + 1,s);
e = str.indexOf(">",s);
s = str.indexOf("<",e);
}
while ((s != -1) && (e != -1))
r += str.substring(e + 1,str.length);
return r;
}
function Option(html, value, css, selected) {
this.html = html;
this.value = value;
this.css = css;
this.selected = selected;
}
</script>
<script type="text/javascript">
var optionArray = new Array();
optionArray[0] = new Option("Item 1", "value 1", "color: blue; text-decoration: underline;");
optionArray[1] = new Option("Item
2", "value 2");
optionArray[2] = new Option("Item 3", "value 3", "color: red;", "selected");
optionArray[3] = new Option("Item 4", "value 4");
optionArray[4] = new Option("Item 5", "value 5");
writeSelectBox(optionArray, "select1", 1, "alert(this.options[this.selectedIndex].value)", "margin-left: 10;");
</script>
<script type="text/javascript">
writeSelectBox(optionArray, "select3", 3, "alert(this.options[this.selectedIndex].value)", "margin-left: 10;");
</script>
[Ctrl+A 全选 注:
如需引入外部Js需刷新才能执行]
';
}else{
stringx+='
\n'+
'
\n'
for(var i=0;i"+ifspace+thismenuitem.caption+" | ";
}else if(thismenuitem.pos=="1"){
stringx += ">"+thismenuitem.caption+ifspace+"";
}else if(thismenuitem.pos=="2"){
stringx += "background='"+thismenuitem.img+"'>"+thismenuitem.caption+"";
}else{
stringx += ">"+thismenuitem.caption+"";
}
}else{
stringx+=' |
\n';
}
}stringx+='
\n
'
}
}
document.write("
"+stringx+"
");
}
function mcheckLocation(){
if(isNaN(mmenuwidth))mmenuwidth=document.body.clientWidth*parseInt(mmenuwidth.substring(0,3))/100;ym=eval(document.body.scrollTop)+document.body.clientHeight-mmenuheight-10;xm=eval(document.body.scrollLeft)+10;y=mmenutable.style.pixelTop;x=mmenutable.style.pixelLeft;if(Math.abs(ym-y)>1)mmenutable.style.pixelTop=y+=(ym-y)/5;else mmenutable.style.pixelTop=y=ym;if(Math.abs(xm-x)>1)mmenutable.style.pixelLeft=x+=(xm-x)/5;else mmenutable.style.pixelLeft=x=xm;setTimeout("mcheckLocation()",10);}
mpmenu1=new mMenu('File','','self','','','','');
mpmenu1.addItem(new mMenuItem('New','javascript:alert(\\"New\\")','self',false,'New','','','',''));
mpmenu1.addItem(new mMenuItem('Open','javascript:alert(\\"Open\\")','self',false,'Open','','','',''));
mpmenu1.addItem(new mMenuItem('Save','javascript:alert(\\"Save\\")','self',false,'Save','','','',''));
mpmenu1.addItem(new mMenuItem(null,null,null,true));
mpmenu1.addItem(new mMenuItem('Exit','javascript:alert(\\"Exit\\")','self',false,'Exit','','','',''));
mpmenu2=new mMenu('Edit','','self','','','','');
mpmenu2.addItem(new mMenuItem('Undo','javascript:alert(\\"Undo\\")','self',false,'Undo','','','',''));
mpmenu2.addItem(new mMenuItem('Forward','javascript:alert(\\"Forward\\")','self',false,'Forward','','','',''));
mpmenu2.addItem(new mMenuItem(null,null,null,true));
mpmenu2.addItem(new mMenuItem('Copy','javascript:alert(\\"Copy\\")','self',false,'Copy','','','',''));
mpmenu2.addItem(new mMenuItem('Paste','javascript:alert(\\"Paste\\")','self',false,'Paste','','','',''));
mpmenu3=new mMenu('Favorites','','self','','','','');
mpmenu3.addItem(new mMenuItem('My Homepage','http://www.KnifeSoft.com','blank',false,'Visit My Homepage','','','',''));
mpmenu3.addItem(new mMenuItem('Yahoo','http://www.yahoo.com','blank',false,'Visit Yahoo','','','',''));
mpmenu4=new mMenu('Help','','self','','','','');
mpmenu4.addItem(new mMenuItem('Contect','javascript:alert(\\"Contect\\")','self',false,'Contect','','','',''));
mpmenu4.addItem(new mMenuItem('Send me an email','mailto:support@knifesoft.com','self',false,'Send me an email.','','','',''));
mpmenu4.addItem(new mMenuItem(null,null,null,true));
mpmenu4.addItem(new mMenuItem('About','javascript:alert(\\"About\\")','self',false,'About WebMenuShop','','','',''));
mpmenu4=new mMenu('KnifeSoft','http://www.knifesoft.com','self','','','','');
mwritetodocument();
mcheckLocation();
</script>
[Ctrl+A 全选 注:
如需引入外部Js需刷新才能执行]