jquery is actually applied to determine if Radio,selelct,checkbox is selected and selected values

Source: Internet
Author: User

1 jquery take radio radio button values2  3$ ("Input[name= ' Items ']:checked"). Val (); 4 another: Determine if Radio is selected and gets the selected value5  6 is as follows:7 functionCheckradio () {8 varItem = $ (": radio:checked"); 9 varlen=item.length;Ten if(len>0){  OneAlert ("yes--selected value is:" +$ (": radio:checked"). Val ());  A }  - }  -   the   -   -   - jquery Radio value, checkbox value, select Value, Radio selected, CheckBox selected, select selected, and its related +   - gets the value of a set of radio selected items +   A  varItem = $ (' input[name=items][checked] '). Val ();  at   - gets the text of the Select selected item -   -  varItem = $ ("Select[name=items] option[selected]"). text ();  -   - the second element of the Select drop-down box is the currently selected value in   -$ (' #select_id ') [0].selectedindex = 1;  to   + Radio The second element of a radio group is the currently selected value -   the$ (' input[name=items] '). Get (1). checked =true;  *   $      Panax Notoginseng Get Value: -   the     +   Atext box, text area: $ ("#txt"). attr ("value")); the   +Multi Box checkbox:$ ("#checkbox_id"). attr ("value")); -   $Radio Group Radio: $ ("input[type=radio][checked")). Val ();  $   -Drop-down box select: $ (' #sel '). Val ();  -   the       -  Wuyi Control form elements: the   -text box, text area: $ ("#txt"). attr ("Value", "');//Clear Content Wu   -$ ("#txt"). attr ("value", ' 11 ');//Populating content About   $      -Multiple marquee checkbox: $ ("#chk1"). attr ("Checked", "");//no tick . -   -$ ("#chk2"). attr ("Checked",true);//Tick A   +  if($ ("#chk1"). attr (' checked ') ==undefined)//To determine if a tick has been made the   -       $   theRadio Group Radio: $ ("Input[type=radio]"). attr ("Checked", ' 2 ');//set the value=2 item as the currently selected item the   theDrop-down box select: $ ("#sel"). attr ("value", '-sel3 ');//set the VALUE=-SEL3 item as the currently selected item the   -$ ("<option value= ' 1 ' >1111</option><option value= ' 2 ' >2222</option>"). AppendTo ("#sel")//option to add a drop-down box in   the$ ("#sel"). empty ();//empty drop-down box the   About       the   the just started to touch jquery, a lot of things are unfamiliar the   +When you use $ ("#id") to get the input element of the page, you find $ ("#id"). Value cannot be taken to values -   the     Bayi   the then finally, with the help of the great Baidu, I found the reason for the problem: the   -$("") is a jquery object, not a DOM element -   the       the   the value is a property of the DOM element the   -     the   the jquery corresponds to the Val the  94      the Val (): Gets the current value of the first matching element.  the   the    98   About Val (val): Sets the value of each matching element.  -  101     102  103 so the code should write this:104   the     106Value: val = $ ("#id") [0].value; 107Assignment: $ ("#id") [0].value = "New Value"; 108  109or $ ("#id"). Val ("New value"));  the  111      the  113Or it can be: val = $ ("#id"). attr ("value"));  the   the   the  117 Each of the jquery is very useful, and it replaces JavaScript's for loop118  119 For example, in a function that has a each, in which a condition is set, the function returns TRUE or false . -  121 functionMethodOne () {122 .... 123$.each (Array,function(){ 124 if(condition established) { the return true; 126 } 127 });  - .... 129 }  the  131 It turns out that it's always wrong.  the  133 After finding the data, it was found that break and continue could not be used within each code block, and that to implement the function of break and continue, the other way134  Break----with returnfalse; 135 Continue--with return ture;136  137 so when I want to use return true to return this function in each, I just let each continue138 even if each is not interrupted, the function cannot return.139   $ another: Determine if Radio is selected and gets the selected value141  142 is as follows:143 functionCheckradio () {144 varItem = $ (": radio:checked"); 145 varlen=item.length;146 if(len>0){ 147Alert ("yes--selected value is:" +$ (": radio:checked"). Val ()); 148 } 149}

jquery is actually applied to determine if Radio,selelct,checkbox is selected and selected values

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.