模仿combox(select)控制項,不用為美化select煩惱了。_經驗交流
來源:互聯網
上載者:User
不用整天為美化select控制項煩惱了。
1、可批量美化select控制項。
2、可以有onchange控制代碼。
3、觸發onchange的函數可帶參數。
3、可以得到select的值。
4、可設定像select類似的捲軸(如大於或等於8個數目時出現捲軸)
5、可設定寬度和高度
API參考:
//首先產生一個simulateSelect的執行個體
//建構函式的第一個選擇性參數為觸發onchange的函數,其它的為onchange函數的參數;
c = new simulateSelect(s1onchange, "never-online");
//設定select的CSS,第一個參數為控制項的主要CSS、第二個為選中條目時的CSS、第三個為沒有選中條目時的CSS
c.style("CtlSelect2", "selected2", "unselected2");
//設定select的寬度和高度;
c.width = 320;
c.height = 20;
//初始化參數為:select控制項的ID,可以用逗號分離,進行批量轉換;
c.init("s1,s2,s3");
下一版本將可修改combox
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML> <HEAD> <TITLE> simulate combox control - http://www.never-online.net </tITLE> <META NAME="Generator" CONTENT="EditPlus"> <META NAME="Author" CONTENT=""> <META NAME="Keywords" CONTENT=""> <META NAME="Description" CONTENT=""> <style> body, input { font-family: verdana; font-size: 9pt; } h1 { font-family: tahoma; font-size: 22pt; text-align: left; } pre { font-size: 9pt; font-family: verdana; border: 1px solid #006600; width: 400px; padding: 10px; background: #ffffff; color: #006600; } .CtlSelect { border: 1px solid #006600; font-family: verdana; height: 20px; color: #006600; background: #ffffff; /*background:url({E5066804-650D-4757-9BA4-A92DB8817A18}0.jpg);*/ } .selected { background: #006600; color: #ffffff; height: 20px; } .unselected { height: 20px; color: #006600; line-height: 120%; border-bottom: 1px solid #006600; } .CtlSelect1 { border: 1px solid #003399; font-family: verdana; height: 20px; color: #003399; background: #ffffff; /*background:url({E5066804-650D-4757-9BA4-A92DB8817A18}0.jpg);*/ } .selected1 { background: #003399; color: #ffffff; height: 20px; } .unselected1 { height: 20px; color: #003399; line-height: 120%; border-bottom: 1px solid #003399; } .CtlSelect2 { border: 1px solid #990000; font-family: verdana; height: 20px; color: #990000; background: #ffffff; /*background:url({E5066804-650D-4757-9BA4-A92DB8817A18}0.jpg);*/ } .selected2 { background: #990000; color: #ffffff; height: 20px; } .unselected2 { height: 20px; color: #990000; line-height: 120%; border-bottom: 1px solid #990000; } .copyright { margin-top: 10px; font-size: 9pt; text-align: center; color: #333; font-weight: bold; } </style> </hEAD> <BODY> <h1> simulate combox control </h1> <h4> demonstrate </h4> <p> normal select: <select id="s0"> <option value="- please select your options -"> - please select your options -</option> <option value="1">option1</option> <option value="2">option2</option> <option value="3">option3</option> <option value="4">option4</option> <option value="5">option5</option> </select> </p> <p> simulate select: <select id="s1"> <option value="- please select your options -"> - please select your options -</option> <option value="1">1option1</option> <option value="2">1option2</option> <option value="3">1option3</option> <option value="4">1option4</option> <option value="5">1option5</option> </select> </p> <p> scroll simulate select: <select id="s2"> <option value="- please select your options -"> - please select your options -</option> <option value="1">2option1</option> <option value="2">2option2</option> <option value="3">2option3</option> <option value="4">2option4</option> <option value="5">2option6</option> <option value="5">2option7</option> <option value="5">2option8</option> <option value="5">2option9</option> <option value="5">2option10</option> <option value="5">2option11</option> <option value="5">2option12</option> <option value="5">2option13</option> <option value="5">2option14</option> </select> </p> <p> onchange handler fire: <select id="s3"> <option value="- please select your options -"> - please select your options -</option> <option value="1">3option1</option> <option value="2">3option2</option> <option value="3">3option3</option> <option value="4">3option4</option> <option value="5">3option5</option> </select> </p> <button onclick="alert(a.getValue('s1') + '\n\n' + b.getValue('s2') + '\n\n' + c.getValue('s3'))" class="CtlSelect"> Get value </button> <button onclick="alert('next version')" class="CtlSelect">append item</button> <button onclick="alert('next version')" class="CtlSelect">remove item</button> <h4> description </h4> <pre class="brush:php;toolbar:false"> //------------------------------------------------------------- // @ Module: simulate select control, IE only. // @ Debug in: IE 6.0 // @ Script by: blueDestiny, never-online // @ Updated: 2006-3-22 // @ Version: 1.0 apha // @ Email: blueDestiny [at] 126.com // @ Website: http://www.never-online.net // @ Please Hold this item please. // // API // @ class: simulateSelect() // // @ object.style(ctlStyle[,selStyle][,unselStyle]) // ctlStyle: main control combox css class name // selStyle: when mouseover or option focus css class name // unselStyle: options blur's css class name // // @ object.width=(widthPX) // widthPX must be a digit number. // // @ object.height=(heightPX) // heightPX must be a digit number. // // @ object.getValue(ctlSelID) // ctlSelID is the unique select control ID // // -------------- for the next Version ---------- // @ object.readOnly = (blnReadOnly) // blnReadOnly must be a boolean type or a number type. // @ object.addEvent(w, h) // w: fire handler's event. // h: handler function. //------------------------------------------------------------- </pre> Power By blueDestiny, never-online http://www.never-online.net </bODY> </hTML>
[Ctrl+A 全選 注:如需引入外部Js需重新整理才能執行]