js select 控制實現(xiàn)代碼
更新時間:2009年04月15日 00:52:50 作者:
用js控制select的一些比較不錯的功能。
實現(xiàn)代碼:
<select id=test11 size=5 style="width:50px"></select>
<select id="test" style="width:50px"></select>
<button onclick='test[test.length]=new Option("1","12");'>同時添加text和value</button>
<button onclick='test.insertBefore(document.createElement("option")).innerText="2";'>對text操作</button> <button onclick='test.appendChild(document.createElement("option")).setAttribute("value","3");'>對value操作</button>
<button onclick="alert(test.outerHTML)">view</button>
<button onclick="test.removeChild(test.children[0])">del1</button>
<button onclick="test.firstChild.removeNode()">del2</button>
<button onclick="test[0]=null">del3</button>
效果演示:
[Ctrl+A 全選 注:引入外部Js需再刷新一下頁面才能執(zhí)行]
復(fù)制代碼 代碼如下:
<select id=test11 size=5 style="width:50px"></select>
<select id="test" style="width:50px"></select>
<button onclick='test[test.length]=new Option("1","12");'>同時添加text和value</button>
<button onclick='test.insertBefore(document.createElement("option")).innerText="2";'>對text操作</button> <button onclick='test.appendChild(document.createElement("option")).setAttribute("value","3");'>對value操作</button>
<button onclick="alert(test.outerHTML)">view</button>
<button onclick="test.removeChild(test.children[0])">del1</button>
<button onclick="test.firstChild.removeNode()">del2</button>
<button onclick="test[0]=null">del3</button>
效果演示:
[Ctrl+A 全選 注:引入外部Js需再刷新一下頁面才能執(zhí)行]
相關(guān)文章
仿51JOB的地區(qū)選擇效果(可選擇多個地區(qū))
以下是HTML網(wǎng)頁特效代碼,點擊運行按鈕可查看效果2008-11-11模擬用戶操作Input元素,不會觸發(fā)相應(yīng)事件
模擬用戶操作Input元素,不會觸發(fā)相應(yīng)事件...2007-05-05鼠標(biāo)移動到某個單元格上后,整個列都變色的實現(xiàn)方法
鼠標(biāo)移動到某個單元格上后,整個列都變色的實現(xiàn)方法...2007-01-01