js select 控制實(shí)現(xiàn)代碼
更新時(shí)間:2009年04月15日 00:52:50 作者:
用js控制select的一些比較不錯(cuò)的功能。
實(shí)現(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");'>同時(shí)添加text和value</button>
<button onclick='test.insertBefore(document.createElement("option")).innerText="2";'>對(duì)text操作</button> <button onclick='test.appendChild(document.createElement("option")).setAttribute("value","3");'>對(duì)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需再刷新一下頁(yè)面才能執(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");'>同時(shí)添加text和value</button>
<button onclick='test.insertBefore(document.createElement("option")).innerText="2";'>對(duì)text操作</button> <button onclick='test.appendChild(document.createElement("option")).setAttribute("value","3");'>對(duì)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需再刷新一下頁(yè)面才能執(zhí)行]
相關(guān)文章
仿51JOB的地區(qū)選擇效果(可選擇多個(gè)地區(qū))
以下是HTML網(wǎng)頁(yè)特效代碼,點(diǎn)擊運(yùn)行按鈕可查看效果2008-11-11模擬用戶操作Input元素,不會(huì)觸發(fā)相應(yīng)事件
模擬用戶操作Input元素,不會(huì)觸發(fā)相應(yīng)事件...2007-05-05[IE&FireFox兼容]JS對(duì)select操作
[IE&FireFox兼容]JS對(duì)select操作...2007-01-01鼠標(biāo)移動(dòng)到某個(gè)單元格上后,整個(gè)列都變色的實(shí)現(xiàn)方法
鼠標(biāo)移動(dòng)到某個(gè)單元格上后,整個(gè)列都變色的實(shí)現(xiàn)方法...2007-01-01文本框點(diǎn)擊時(shí)文字消失,失去焦點(diǎn)時(shí)文字出現(xiàn)
這個(gè)功能主要用戶搜索關(guān)鍵字框中,提示用戶輸入關(guān)鍵字,代碼清晰,比原理的功能要好很多,推薦使用2008-09-09javascrip客戶端驗(yàn)證文件大小及文件類型并重置上傳
為了提高效率,很多時(shí)候需要在web頁(yè)面中對(duì)客戶端上傳的文件進(jìn)行驗(yàn)證,然后再上傳到服務(wù)器。2011-01-01