Select下拉列表框(添加、删除option)
??? 這是一個實現Select下拉列表框(添加、刪除option) 的實例代碼,新手朋友可以學習一下,
<select?id=/"s1/"?size=/"5/"?multiple=/"multiple/">
????<option?value=/"11111/">11111</option>
????<option?value=/"22222/">22222</option>
????<option?value=/"33333/">33333</option>
????<option?value=/"44444/">44444</option>
????<option?value=/"55555/">55555</option>????
</select>
<select?id=/"s2/"?size=/"5/"?multiple=/"multiple/">
</select>
<br?/><br?/>
<input?type=/"button/"?value=/"添加/"?οnclick=/"AddOrRomove(’add’);/"?/>
<input?type=/"button/"?value=/"刪除/"?οnclick=/"AddOrRomove(’remove’);/"?/>
?
?
<script?language=/"javascript/"?type=/"text/javascript/">
function?AddOrRomove(action)
{
????var?s1?=?document.getElementById(/"s1/");
????var?s2?=?document.getElementById(/"s2/");
????var?optionArray?=?new?Array();
????
????if?(action?==?/"add/")?//添加
????{
????????for?(var?i=0;i<s1.options.length;i++)
????????{
????????????if?(s1.options[i].selected?==?true)
????????????{optionArray.push(s1.options[i]);}
????????}
????????
????????for?(var?j?in?optionArray)
????????{
????????????optionArray[j].selected?=?false;
????????????s2.options.appendChild(optionArray[j]);
????????}
????}
????else?if?(action?==?/"remove/")?//刪除
????{
????????for?(var?i=0;i<s2.options.length;i++) [Page]
????????{
????????????if?(s2.options[i].selected?==?true)
????????????{optionArray.push(s2.options[i]);}
????????}
????????
????????for?(var?j?in?optionArray)
????????{
????????????optionArray[j].selected?=?false;
????????????s1.options.appendChild(optionArray[j]);
????????}????????
????}
}
</script>
?
《新程序員》:云原生和全面數字化實踐50位技術專家共同創作,文字、視頻、音頻交互閱讀總結
以上是生活随笔為你收集整理的Select下拉列表框(添加、删除option)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: ASP程序实现网页伪静态页源代码
- 下一篇: ASP调用带参数存储过程的几种方式