Jquery+php gets the text and value of select option Trade-offs (with Select City instance)

Source: Internet
Author: User
Jquery+php gets the text and value selected by Select option (with Select City instance)


PHP Code:

                 
  • Location of the city Choose your city <%foreach from= $supportcity item=city key=k%>selected<%/if%> ><%$city.city_name%> <%/foreach%>
  • value="<%$k%>">selected<%/if%> ><%$city.city_name%> <%/foreach%> >
  • area <%foreach from= $supportcity item=city key=k%> Choose your area <%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 ();        

    Here are the details:

    jquery Radio value, checkbox value, select Value, Radio selected, CheckBox selected, select selected, and its related settings

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

    gets the text of the Select selected item:var item = $ ("Select[name=items] option[selected]"). Text (); or $ ("Select[name=items]"). Find ("option:selected"). Text ();

    the second element of the Select drop-down box is the currently selected value:$ (' #select_id ') [0].selectedindex = 1;

    Select drop-down box value = ' val ' element is currently selected:$ ("Select[name=items] option[value= ' Val ']"). attr ("Selected", "Selected");

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

    Radio value = ' val ' element is currently selected:$ (' input[name=items] [value= ' Val '] '). attr ("Checked", "checked");


    Get Value:

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

    multiple Marquee checkbox:$ ("Input[name= ' checkbox ': Checked]"). each (function () {

    var val = $ (this). Val ();

    });

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

    The value of the drop-down box select is: $ (' select '). val ();

    Drop -down box select the text value selected:$ ("select"). Find ("option:selected"). Text ();

    Control form elements:

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

    $ ("#txt"). attr ("value", ' 11′ '); Populating content

    Multiple marquee checkbox:
    the second element of the checkbox is ticked:$ ("Input[name=items]"). Get (1). checked = true; Tick
    $ ("Input[name=items]"). Get (1). checked = false; No tick.

    checkbox of value= ' val ' element before tick:$ ("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)//Determine if a tick has been made

    Radio Group Radio: $ ("Input[type=radio]"). attr ("Checked", ' 2′ ');//Set value=2 items as the current selection

    Drop- down box select: $ ("#sel"). attr ("value", '-sel3′ ');//Set the VALUE=-SEL3 item as the current selection

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

    $ ("#sel"). empty ();//Empty drop-down box

    jquery Gets the value of the radio selection


    Code

    $ ("Input[name= ' Radio_name '][checked]"). Val (); Select the value of the selected radio
    $ ("#text_id"). focus (function () {//code ...}); Event triggered when object text_id gets focus
    $ ("#text_id"). blur (function () {//code ...}); Event triggered when object text_id loses focus
    $ ("#text_id"). Select (); Make the Vlaue value of the text box selected
    $ ("Input[name= ' radio_name '][value= ' to select Radio Value '").
    attr ("Checked", true); Set Radio to selected based on value values

    jquery Gets the value of the checkbox selection

    $ ("Input[name= ' Checkbox_name '][checked]"); Select a collection of selected checkbox elements if you want value values you need to traverse this collection
    $ ($ ("Input[name= ' Checkbox_name '][checked]")).
    each (function () {arrchk+=this.value + ', ';}); /Traverse the collection of selected checkbox elements to get value values
    $ ("#checkbox_id"). attr ("checked"); Gets the status of a checkbox (there is no selection, return true/false)
    $ ("#checkbox_id"). attr ("Checked", true); Set the status of a checkbox to checked (checked=true)
    $ ("#checkbox_id"). attr ("checked", false); Set the status of a checkbox to unchecked (Checked=false)
    $ ("Input[name= ' Checkbox_name ']"). attr
    ("Checked", $ ("#checkbox_id"). attr ("checked"));//According to the 3,4,5 bar, you can analyze the meaning of this Code
    $ ("#text_id"). Val (). Split (","); Returns an array of value values of text as ', ' delimited

    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.