Talking about option's emptying in <select > objects
Number of intlength as option: document.all ("Lstuserid"). Options.length;
Lstuserid for <select id=lstuserid> objects:
<select id=lstuserid>
<option >1</option>
<option >3</option>
<option >4</option>
</select>
Method One:
for (var i=0; i<intlength-1;i++)
{
document.all ("Lstuserid"). Options.remove (i);
}
Method Two:
while (document.all ("Lstuserid"). options.length>0)
{
document.all ("Lstuserid"). Option.remove (0);
}
Method one cannot empty the <select id=lstuserid> object and will make an error. Because when document.all ("Lstuserid"). Options[0] is deleted document.all ("Lstuserid"). Options[intlength-1] That is, the last option ceases to exist.
So from the last delete can be from the first deletion of the problem.
And method Two is able to empty because document.all ("Lstuserid"). Options[0] After the deletion of document.all ("Lstuserid"). Options[1] became document.all (" Lstuserid "). Options[0]. Until the last one is deleted.
#结束
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service