模仿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 <meta name="Generator" content="EditPlus"><meta name="Author" content=""><meta name="Keywords" content=""><meta name="Description" content=""><br /><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><p><br /> simulate combox control demonstrate <p>normal select:<br /><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>simulate select:<br /><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>scroll simulate select:<br /><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>onchange handler fire:<br /><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><br /><button onclick="alert('next version')" class="CtlSelect">append item</button><br /><button onclick="alert('next version')" class="CtlSelect">remove item</button> </p> description <pre> //------------------------------------------------------------- // @ 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 </p><p>http://www.never-online.net</p><p>

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.