Jquery returns the value of the Radio radio button $ ("input [name = 'items ']: checked "). val (); and: judge whether radio is selected and obtain the selected value as follows: function checkradio () {var item = $ (": Radio: checked "); vaR Len = item. length; If (LEN> 0) {alert ("Yes -- the selected value is:" + $ (": Radio: checked "). val () ;}} jquery radio value, checkbox value, select value, Radio selected, checkbox selected, select selected, obtain the value of a set of Radio selected items var item =$ ('input [name = items] [checked] '). val (); get the text var item of the selected select item =$ ("select [name = Items] Option [selected] "). text (); the second element in the select drop-down box is the currently selected value $ ('# select_id') [0]. selectedindex = 1; the second element of the radio Radio Group is the currently selected value $ ('input [name = items] '). get (1 ). checked = true; Value: text box, text area: $ ("# TXT "). ATTR ("value"); multiple choice box checkbox: $ ("# checkbox_id "). ATTR ("value"); Radio Group radio: $ ("input [type = radio] [checked]"). val (); drop-down box select: $ ('# sel '). val (); control form element: text box, text area: $ ("# TXT "). ATTR ("value", ''); // clear the content $ (" # TXT "). ATTR ("value", '11' ); // Select the multiple-choice box for filling in the content: $ ("# CHK1 "). ATTR ("checked", ''); // do not tick $ (" # CHK2 "). ATTR ("checked", true); // tick if ($ ("# CHK1 "). ATTR ('checked') = undefined) // determines whether the radio group radio has been checked: $ ("input [type = radio]"). ATTR ("checked", '2'); // select: $ ("# Sel") for the project whose value is set to 2 "). ATTR ("value", '-sel3 '); // set the value =-sel3 project to the currently selected item $ ("<option value = '1'> 1111 </option> <option value = '2'> 2222 </ option> "). appendto ("# Sel") // Add option $ ("# Sel") in the drop-down box "). E Mpty (); // clear the drop-down box and get started with jquery. Many things are unfamiliar when you use $ ("# ID") to obtain the page input element, found $ ("# ID "). the value cannot be obtained. Later, with the help of the great Baidu, the cause of the problem was found: $ ("") is a jquery object, instead of a DOM element value, jquery corresponds to the DOM element attribute Val (): obtains the current value of the First Matching Element. Val (VAL): sets the value of each matching element. So,Code It should be written as follows: Value: val = $ ("# ID") [0]. value; Value: $ ("# ID") [0]. value = "New Value"; or $ ("# ID "). val ("New Value"); or you can: val = $ ("# ID "). ATTR ("value"); In jquery, each is very useful. It is often used to replace JavaScript's for loop. For example, if there is an each in a function and some condition in each is true, returns the true or false function methodone (){.... $. each (array, function () {If (condition true) {return true ;}});....} it turns out that it is always incorrect. Later, I found that break and continue cannot be used in the each code block. To implement the break and continue functions, I need to use other methods break ---- return false; continue -- use return ture; so when I want to use return true in each to return to this function, it is actually to let the each continue to execute without interrupting the each, therefore, the function cannot return. In addition, the function checkradio () {var item = $ (": Radio: checked") is used to determine whether radio is selected and obtain the selected value "); vaR Len = item. length; If (LEN> 0) {alert ("Yes -- the selected value is:" + $ (": Radio: checked "). val ());}}
From: http://www.oschina.net/code/snippet_179497_6635
<! Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <HTML xmlns = "http://www.w3.org/1999/xhtml">
from: http://blog.csdn.net/snihcel/article/details/7454221
The following describes a lot of methods for jquery to obtain the select attribute. In the following example, jquery gets the drop-down box value and select text code. Obtain the selected text and value by jquery select: Obtain the selected text: $ ("# ddlregtype "). find ("option: Selected "). text (); obtain the value selected by the SELECT statement: $ ("# ddlregtype "). val (); obtain the selected index of the SELECT statement: $ ("# ddlregtype "). get (0 ). selectedindex; select: select the selected index: $ ("# ddlregtype "). get (0 ). selectedindex = index; // index: select the selected value for the index value: $ ("# ddlregtype "). ATTR ("value", "normal"); $ ("# ddlregtype "). val ("normal"); $ ("# ddlregtype "). get (0 ). value = Value; select the selected text: var COUNT = $ ("# ddlregtype option "). length; For (VAR I = 0; I <count; I ++) {if ($ ("# ddlregtype "). get (0 ). options [I]. TEXT = text) {$ ("# ddlregtype "). get (0 ). options [I]. selected = true; break; }}$ ("# select_id option [TEXT = 'jquery ']"). ATTR ("selected", true); Set select option item: $ ("# select_id "). append ("<option value = 'value'> text </option>"); // Add an option $ ("# select_id "). prepend ("<option va Lue = '0'> select </option> "); // insert an option $ (" # select_id option: Last "). remove (); // delete option $ ("# select_id option [Index = '0']") with the largest index value. remove (); // delete option $ ("# select_id option [value = '3']") where the index value is 0. remove (); // delete option $ ("# select_id option [TEXT = '4']") with a value of 3. remove (); // Delete select: $ ("# ddlregtype "). empty (); to work, you need to obtain the values in the two forms. How do I obtain the value added from the left-side selection box to the right-side selection box? I thought about how to use webpage special effects. Here I use jquery, which is quite popular. The JS Code is as follows: // obtain all attribute values var item =$ ("# select1 "). val (); $ (function () {$ ('# select1 '). each (// obtain all values of select1 function () {$ ('click '). click (function () {alert ($ ('# select2 '). val (); // obtain the select1 value in select2});}) </SCRIPT> it is worth noting that you cannot directly write $ (function () {$ ('# select2 '). each (// obtain all values of select1, because the options are added from the left to the right, jquery does not actually pass the value from the left to the right. Function () {$ ('click '). click (function () {alert ($ (this ). val (); // obtain the select1 value in select2}) ;}) HTML: <Div class = "centent"> <select multiple = "multiple" id = "select1" name = "DD" style = "width: 100px; Height: 160px; "> <option value =" 1 "> Option 1 </option> <option value =" 2 "> Option 2 </option> <option value =" 3 "> Option 3 </option> <option value = "4"> Option 4 </option> <option value = "5"> Option 5 </option> <option value = "6"> option 6 </option> <option value = "7"> Option 7 </option> </SELECT> <div> <span id = "add"> select Add to right>> </span> <span id = "add_all"> Add all to the right> </span> </div> <Div class = "centent"> <select multiple = "multiple" id = "select2" name = "Sel" style = "width: 100px; Height: 160px; "> </SELECT> <div> <span id =" Remove "> <selected to be deleted to the left </span> <span id =" remove_all "> <all deleted left </span> </div>
from: http://blog.csdn.net/snihcel/article/details/7454950