Jquery drop-down select control operation method sharing

Source: Internet
Author: User

This article mainly introduces the jquery drop-down select control operation method sharing (jquery operation select). For more information, see

JQuery's method of obtaining and setting Select Options is summarized as follows: Code: $ ("# select_id "). change (function () {// code ...}); // Add an event for Select. When one of the Select events is selected, var checkText =$ ("# select_id") is triggered "). find ("option: selected "). text (); // obtain the Textvar checkValue selected by Select = $ ("# select_id "). val (); // obtain the Valuevar checkIndex selected by Select = $ ("# select_id "). get (0 ). selectedIndex; // obtain the selected index value var maxIndex =$ ("# select_id option: last "). attr ("index"); // obtain the maximum index value of Select $ ("# select_id "). get (0 ). selectedIndex = 1; // Select $ ("# select_id") for items whose Select index value is 1 "). val (4); // Select a Value of 4 from Select $ ("# select_id option [text = 'jquery ']"). attr ("selected", true); // set the Select Text value to jQuery and select the selected text. The Code is as follows: $ ("# ddlRegType "). find ("option: selected "). text (); obtain the value selected by the select statement. The Code is as follows: $ ("# nowamagic "). val (); obtain the index selected by the select statement. The Code is as follows: $ ("# nowamagic "). get (0 ). selectedIndex; Set select jQuery to add/delete Select Option items: the code is as follows: $ ("# select_id "). append ("<option value = 'value'> Text </option>"); // append an Option for Select (drop-down) $ ("# select_id "). prepend ("<option value = '0'> Select </option>"); // insert an Option for Select (first position) $ ("# select_id option: last "). remove (); // Delete the maximum Option (last) of the index values in the Select statement $ ("# select_id option [index = '0']"). remove (); // delete Option (first) with the index value 0 in Select $ ("# select_id option [value = '3']"). remove (); // delete Option $ ("# select_id option [text = '4']") of Value = '3' in Select. remove (); // Delete the Select Option set '4' in the select statement. The Code is as follows: // index is the index value $ ("# nowamagic "). get (0 ). selectedIndex = index; set the value selected by select: the code is as follows: $ ("# nowamagic "). attr ("value", "Normal"); $ ("# nowamagic "). val ("Normal"); $ ("# nowamagic "). get (0 ). value = value; select the selected text: the code is as follows: var count = $ ("# nowamagicoption "). length; for (var I = 0; I <count; I ++) {if ($ ("# nowamagic "). get (0 ). options [I]. text = text) {$ ("# nowamagic "). get (0 ). options [I]. selected = true; break;} Clear select: the code is as follows: $ ("# nowamagic "). empty ();

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.