jquery operates the Select option collection to determine whether the option is present in the collection

Source: Internet
Author: User

Reprint: http://www.cnblogs.com/pepcod/archive/2012/07/03/JavaScript.html

Query gets the text and value of the Select selection:
Syntax Explanation:

1. $ ("#select_id"). Change (function () {//code ...});    Adds an event for select, triggering 2 when one of the items is selected. var checktext=$ ("#select_id"). Find ("option:selected"). Text ();   Gets the Text3 selected by the Select. var checkvalue=$ ("#select_id"). Val ();   Gets the Value4 selected by the Select. var checkindex=$ ("#select_id"). Get (0). SelectedIndex;   Gets the index value of the select selection of 5. var maxindex=$ ("#select_id option:last"). attr ("index");   Gets the maximum index value of the Select

jquery sets the text and value selected for select:

Determine if the item value= "Paravalue" exists in the Select option

function Jsselectisexititem (objselect) {varIsexit =false; for(vari =0; I < objselect.size (); i++) {if(Objselect[i].value = =5) {Isexit=true; Break;}}returnIsexit;} if(Jsselectisexititem (Objselect)) {//If there is a value=5 option, remove the$("#cardType option[value= ' 5 ']"). Remove (); }


Syntax Explanation:

1  $ ("#select_id"). Get (0). selectedindex=1;   Set the Select index value to 1 to select 2  $ ("#select_id"). Val (4);    Select 3  $ ("#select_id option[text= ' jQuery ') ' for the item with value 4 for select. attr (" selected ", true);    
jquery Add/Remove option for select:
Syntax Explanation:
1  $ ("#select_id"). Append ("<option value= ' value ' >Text</option>");   Append an option (drop-down) of 2  $ ("#select_id") for select. Prepend ("<option value= ' 0 ' > Please select </option>");   Insert an option (first position) for select 3  $ ("#select_id option:last"). Remove ();   Delete the index value in select maximum option (last) 4 $ ("#select_id option[index= ' 0 ']"). Remove ();   Delete option with index value 0 in select (first) 5 $ ("#select_id option[value= ' 3 ']"). Remove ();   Delete Option6 $ ("#select_id option[text= ' 4") for value= ' 3 ' in select. Remove ();   Delete option for text= ' 4 ' in select

jquery operates the Select option collection to determine whether the option is present in the collection

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.