JQuery + PHP get the Text and Value of the Selectoption trade-off (with the selected city instance)

Source: Internet
Author: User
JQuery + PHP get the Text and Value selected by Selectoption (with the selected city instance attached) PHP code: & lt; li & gt; & lt; spanclass & quot; l2 & quot; & gt; city & lt; span & gt; & jQuery + PHP obtain the Text and Value selected by Select option (see Select city instance)


PHP code:

                 
  • City Select the city<% Foreach from = $ supportcity item = city key = k %>Selected <%/if % >>< % $ city. city_name %><%/Foreach %>
  • Region <% foreach from = $ supportcity item = city key = k %> Select Region<% Foreach from = $ city. areas item = area %><% $ Area. area %><%/Foreach %><%/Foreach %>

  • Jquery code:

            $("select.city").change(function(){            var ccode = $(this).val();            $("select.area").hide();            if(ccode){                $("select.area[citycode="+ccode+"]").show();            }        });        var sltcity = $("select.city").val();        if(sltcity){             $("select.area[citycode="+sltcity+"]").show();        }

    The following is a detailed description:

    Jquery radio, checkbox, select, radio, checkbox, select, and related settings

    Obtain the value of a set of radio selected items: var item =$ ('input [name = items] [checked] '). val ();
    Obtain the text of the selected select item: var item =$ ("select [@ name = items] option [@ selected]"). text ();

    Obtain the text of the selected select item: var item =$ ("select [name = items] option [selected]"). text (); or $ ("select [name = items]"). find ("option: selected "). text ();

    The second element in the select drop-down box is the selected value: $ ('# select_id') [0]. selectedIndex = 1;

    The select drop-down box value = 'Val' element is the current selected item: $ ("select [name = items] option [value = 'Val']"). attr ("selected", "selected ");

    The second element of the radio Group is currently selected: $ ('input [@ name = items] '). get (1 ). checked = true; or $ ('input [name = items] '). attr ("checked", '1 ′);

    The value = 'Val' element of radio is currently selected: $ ('input [name = items] [value = 'Val'] '). attr ("checked", "checked ");


    Get value:

    Text box, text area: $ ("# txt"). attr ("value ");

    Multiple choice box checkbox: $ ("input [name = 'checkbox': checked]"). each (function (){

    Var val = $ (this). val ();

    });

    Radio Group radio: $ ("input [type = radio] [checked]"). val ();

    Value of select in the drop-down box: $ ('select'). val ();

    Select the selected text value in the drop-down box: $ ("select"). find ("option: selected"). text ();

    Control form elements:

    Text box, text area: $ ("# txt"). attr ("value", "); // clear the content

    $ ("# Txt"). attr ("value", '11'); // fill in the content

    Multiple selection box checkbox:
    The second element of the checkbox is checked: $ ("input [name = items]"). get (1). checked = true; // Check
    $ ("Input [name = items]"). get (1). checked = false; // do not check

    Check the value = 'Val 'element of the checkbox: $ ("input [name = item] [value = 'Val']"). attr ("checked", true); or $ ("input [name = item] [value = 'Val']"). attr ("checked", "checked ");

    If ($ ("input [name = item] [value = 'Val']"). attr ('checked') = true) // You can check whether a check is performed.

    Radio Group radio: $ ("input [type = radio]"). attr ("checked", '2'); // set the project with value = 2 as the currently selected item

    Drop-down box select: $ ("# sel"). attr ("value", '-sel3'); // set the value =-sel3 project to the currently selected item

    $ ("2222"). AppendTo (" # sel ") // add the option in the drop-down box

    $ ("# Sel"). empty (); // clear the drop-down list

    JQuery obtains the Value selected by Radio.


    Code

    $ ("Input [name = 'Radio _ name'] [checked]"). val (); // select the Value of the selected radio
    $ ("# Text_id"). focus (function () {// code...}); // event triggered when the object text_id gets the focus
    $ ("# Text_id"). blur (function () {// code...}); // triggered when the focus of the object text_id is lost
    $ ("# Text_id"). select (); // Set the Vlaue value of the text box to the selected status.
    $ ("Input [name = 'Radio _ name'] [value = 'value to select the Value of radio '").
    Attr ("checked", true); // Set Radio to the selected status based on the Value.

    JQuery obtains the Value selected by the CheckBox.

    $ ("Input [name = 'checkbox _ name'] [checked]"); // select the set of checked checkbox elements. if you want to get the Value, you need to traverse the set.
    $ ("Input [name = 'checkbox _ name'] [checked]").
    Each (function () {arrChk + = this. value + ',' ;}); // traverses the set of checked CheckBox elements to obtain the Value.
    $ ("# Checkbox_id"). attr ("checked"); // gets the status of a CheckBox (true/false if any CheckBox is selected)
    $ ("# Checkbox_id"). attr ("checked", true); // Set the status of a CheckBox to select (checked = true)
    $ ("# Checkbox_id"). attr ("checked", false); // Set the status of a CheckBox to unselected (checked = false)
    $ ("Input [name = 'checkbox _ name']"). attr
    ("Checked", $ ("# checkbox_id"). attr ("checked"); // You can analyze the meaning of the code based on 3, 4, and 5.
    $ ("# Text_id"). val (). split (","); // returns an array separated ','.

    Jquery1.3.2

    ISDARK: $ ("input [@ type = radio] [name = ISDARK] [checked]"). val ()

    $ ("Input [name = radioname] [value = radio value]"). attr ("checked", "checked ");



    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.