Implementation Code of jQuery Operation option _ jquery-js tutorial

Source: Internet
Author: User
In js, clear option before option is cleared. My approach is to traverse the existing option and leave each sub-element empty. In js, clear option before option is cleared. My approach is to traverse the existing option and leave each sub-element empty. Now we use jQuery to implement it. We only need to call the empty method supported by jQuery.

Empty ()

Delete all child nodes in the matched element set.
In addition, we need to set the default value. So here we can clear all the options in the select statement and use the following statement:

The Code is as follows:


$ ('# Selectid'). empty (). append ($ ("Set the default value here."));


Create option dynamically in js
The previous method was to use its intermediate function to traverse json objects returned by Ajax. And use the new Option to create the option. Now I use the following method to handle it:

The Code is as follows:


For (var I = 0, len = jsondata. length; I $ ('# Selectid'). append ($ (" "Maid +""));
}


It seems that you can write it like this:

The Code is as follows:


$ ('# Selectid'). append (""Maid +"");

Related Article

Contact Us

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

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.