Gets the selected value
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 ();
The second element of the Select drop-down box is the currently selected value
$ (' #select_id ') [0].selectedindex = 1;
Radio the second element of a radio group is the currently selected value
$ (' input[@name =items] '). Get (1). checked = true;
Get Value:
text box, text area:
$ ("#txt"). attr ("value");
$ ("#txt"). Val ();
Multiple marquee 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 Contents
$ ("#txt"). attr ("value", ' 11 ');//fill content
Multiple marquee checkbox:
$ ("#chk1"). attr ("Checked", "");//Not ticked
$ ("#chk2"). attr ("Checked", true);//tick
if ($ ("#chk1"). attr (' checked ') ==undefined)//Determine if a tick has been made
Radio Group Radio:
$ ("input[@type =radio]"). attr ("Checked", ' 2 ');//Set value=2 for the currently selected item
Drop-down box select:
$ ("#sel"). attr ("value", '-sel3 ');//Set the VALUE=-SEL3 item as the current selection
$ ("<optionvalue= ' 1 ' >1111</option><optionvalue= ' 2 ' >2222</option>"). AppendTo ("#sel")// option to add a drop-down box
$ ("#sel"). empty ();//Empty drop-down box
=====================
In jquery, use $ ("#id") to get the input element of the page, which is equivalent to document.getElementById ("element") However, it is a jquery object instead of a DOM The element object. Value is a property of the DOM element object. Therefore, use $ ("#id"). Value cannot be taken as a value by the following method:
Value:
val = $ ("#id") [0].value;
$ ("#id") [0].value = "New value";
Assignment value:
$ ("#id") [0].value = "New value";
or $ ("#id"). Val ("new value");
val = $ ("#id"). attr ("value");
jquery input Text Radio Check Select operation
[XHTML] view Plaincopy
- <! 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">
- <head>
- <Meta http-equiv= "content-type" content= "text/html; Charset=utf-8 " />
- <title> Untitled document </title>
- <mce:script src="jquery-starterkit/lib/jquery-1.3.2.min.js" mce_src= "jquery-starterkit/ Lib/jquery-1.3.2.min.js " type=" Text/javascript "></mce:script>
- </head>
- <body>
- <input type="text" id="dd" name="dd" value="DDS"/>dd
- <input name="RR" id= "rr" type= "Radio" value=" />ff"
- <input name="RR" id= "rr2" type="Radio" value="4" />55
- <input name="ff" type="checkbox" value="AA" />jgdg
- <input name="ff" type="checkbox" value="GD" />jgdg
- <select name="ss" id="ss" size="1">
- <option value= ""></option>
- <option value="8">d</option>
- <option value="2">g</option>
- </Select>
- <br/>
- <input type="button" id= "button" value="buttons One" />
- <input type="button" id="JJ" value="pushbutton two" />
- <br/>
- <div id="SSD">fgfoohello</div>
- </body>
- <mce:script language="javascript" type="Text/javascript"><!--
- $ (function () {
- $ ("#button"). Click (function () {
- Get value
- Alert ($ (' #dd '). Val ());//type=text
- Alert ($ (' input[name=rr][checked] '). Val ());//type=Radio
- Alert ($ (' input[name=ff][checked] '). Val ());//type=checkbox
- Alert ($ ("select[name=SS] option[selected]"). Val ());//select is equal to alert ($ ("#ss option[selected]"). Val ());
- Get text
- Alert ($ ("select[name=SS] option[selected]"). text ());//select
- Control
- /*//Disable #dd Disabled
- $ ("#dd"). attr ("Disabled", "disabled");
- Enable #dd unblock
- $ ("#jj"). Removeattr ("Disabled"); */
- $ (' input[name=RR] '). Get (0). checked = true;//The first radio is selected
- Alert ($ ("input[type=radio][value=)"). attr ("Checked", ' checked '));//value= 34 of Radio are selected
- Alert ($ ("input[type=checkbox][value=gd]"). attr ("Checked", ' checked '));//value= GD's checkbox is selected
- $ (' input[name=ff] '). Get (1). checked = true;//The first check is selected
- /*//option is selected according to the text of option
- count=$ ("#ss"). Find ("option"). Length;
- for (Var i=0;i<count;i++)
- {
- if ($ ("#ss"). Get (0). options[i]. Text = = ' d ')
- {
- $ ("#ss"). Get (0). Options[i]. selected = true;
- Break
- }
- } */
- //$ ("<option Value= ' 1 ' >1111</ option><option < span class= "attribute" >value= ">22s22 </option> "). AppendTo (" #ss ");//add option
- $ ("#ss option[value=8]"). Remove ("");//Remove <option value=' 8 '>d</ Option>
- $ ("#ss"). attr ("Value", ' 2 ');//SELECT option
- $ (' #ss ') [0]. SelectedIndex = 1;//Select option
- $ ("#ss"). empty ();//Clear All option
- /*//replacing text
- var $Thirdlink = $ ("#ssd");
- var linkText = $thirdLink. Text (). replace (' foo ', ' Bar ');
- $thirdLink. Text (LinkText); */
- });
- });
- --></mce:script>
- </html>