从选择列表中清除所有选项组和选项 [英] Clear all optgroups and options from a select list

查看:96
本文介绍了从选择列表中清除所有选项组和选项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个多选列表,它是根据asp页面上的先前选择动态创建的。我要做的第一件事就是通过


document.form1.itemcross.length = 0;


的治疗选项列表>
唯一的问题是它离开了optgroups。我如何获得

摆脱选择组?


谢谢

BrianD

I have a multiple select list that is created dynamically based on a
previous selection on an asp page. The first thing I do is to clear
the curent option list by

document.form1.itemcross.length = 0;

The only problem is that it leaves the optgroups. How do I also get
rid of the optgroups?

Thanks
BrianD

推荐答案

Brian D写道:
Brian D wrote:

我有一个基于
在asp页面上的先前选择。我要做的第一件事就是通过


document.form1.itemcross.length = 0;


的治疗选项列表>
唯一的问题是它离开了optgroups。我如何获得

摆脱选择组?


谢谢

BrianD
I have a multiple select list that is created dynamically based on a
previous selection on an asp page. The first thing I do is to clear
the curent option list by

document.form1.itemcross.length = 0;

The only problem is that it leaves the optgroups. How do I also get
rid of the optgroups?

Thanks
BrianD



你需要一个对象的id或对它的引用:


< script>

//通过引用删除一个对象

function del(element){element.parentNode.removeChild(elemen t);}

//通过id获取对象的引用:

function

You need an id for the object or a reference to it:

<script>
// delete an object by reference
function del(element){element.parentNode.removeChild(elemen t);}
// Get a reference to an object by id:
function


(id){return document.getElementById(id);}
//按ID删除对象:

function
(id){return document.getElementById(id);}
// Delete an object by id:
function


del(id){x =
del(id){x=


这篇关于从选择列表中清除所有选项组和选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆