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

Source: Internet
Author: User

jquery takes radio the value of the radio button $ ("Input[name= ' Items ']:checked"). Val (); Another: Determine if Radio is selected and gets the selected value as follows:functionCheckradio () {varItem = $ (": radio:checked"); varlen=item.length;if(len>0) {alert ("yes--selected value is:" +$ (": radio:checked"). Val ()); }} jquery Radio value, checkbox value, select Value, Radio selected, CheckBox selected, select selected, and its related get a set of radio values of the selected itemvarItem = $ (' input[name=items][checked] '). Val (); Gets the text of the Select selected itemvarItem = $ ("Select[name=items] option[selected]"). text (); The second element of the Select drop-down box is the current check value of $ (' #select_id ') [0].selectedindex = 1; Radio the second element of the radio group is the current check value of $ (' Input[name=items] '). Get (1). checked =true; Get Value: text box, text area: $ ("#txt"). attr ("value")); Multi Box checkbox:$ ("#checkbox_id"). attr ("value")), Radio Group Radio: $ ("Input[type=radio][checked]"). Val (); Drop-down box select: $ (' #sel '). Val (); Control form elements: text box, text area: $ ("#txt"). attr ("Value", "');//Clear Content $("#txt"). attr ("value", ' 11 ');//Populating contentMulti Marquee checkbox: $ ("#chk1"). attr ("Checked", "');//no tick .  $("#chk2"). attr ("Checked",true);//Tick  if($ ("#chk1"). attr (' checked ') ==undefined)//To determine if a tick has been madeRadio Group Radio: $ ("Input[type=radio]"). attr ("Checked", ' 2 ');//set the value=2 item as the currently selected itemDrop -down box select: $ ("#sel"). attr ("value", '-sel3 ');//set the VALUE=-SEL3 item as the currently selected item  $("<option value= ' 1 ' >1111</option><option value= ' 2 ' >2222</option>"). AppendTo ("#sel")//option to add a drop-down box $("#sel"). empty ();//empty drop-down boxjust beginning to touch jquery, a lot of things are unfamiliar in using $ ("#id") to get the input element of the page, find the $ ("#id"). Value cannot be taken to a value later finally, with the help of the great Baidu, found the cause of the problem: $ ("") is a jquery object, not a DOM element value is the property of the DOM element jquery corresponds to the Val val (): Gets the current value of the first matching element.         Val (val): Sets the value of each matching element. So, the code should write: value: Val= $ ("#id") [0].value; Assignment: $ ("#id") [0].value = "New Value"; or $ ("#id"). Val ("New value").); Or it can also be: Val= $ ("#id"). attr ("value")); Each of these is very useful in jquery, and it is used to replace JavaScript for loops. For example, in a function that has a each, the function returns TRUE or False if a certain condition is set in each .functionMethodOne () {.... $.each (Array,function(){ if(condition established) {return true; } });  .... }  It turns out that it's always wrong. 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 way Break----with returnfalse; Continue--with return ture; So when I want to use return true to return to this function in each, I just let each continue execution and even if each is not interrupted, so the function can not return the other: Determine whether Radio is selected and get the selected value as follows: functionCheckradio () {varItem = $ (": radio:checked"); varlen=item.length;if(len>0) {alert ("yes--selected value is:" +$ (": radio:checked"). Val ()); } } 

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.