jquery operation input

Source: Internet
Author: User

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 the value=2 item as 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>& lt;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 to the values: val = $ ("#id") [0].value;$ ("#id") [0].value = " New value "; Assignment: $ (" #id ") [0].value =" New value ";
or $ ("#id"). Val ("new value"); val = $ ("#id"). attr ("value");

==================================

jquery input Text Radio Check Select operation2009-04-29 15:36<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 "/>
<title> Untitled Document </title>

<script src= "Jquery-starterkit/lib/jquery-1.3.2.min.js" type= "Text/javascript" ></script>


<body>
<input type= "text" id= "DD" name= "DD" value= "DDS"/>dd

<input name= "RR" id= "RR" type= "Radio" value= "/&GT;FF"
<input name= "RR" id= "RR2" type= "Radio" value= "4"/>55

<input name= "ff" type= "checkbox" value= "AA"/&GT;JGDG
<input name= "ff" type= "checkbox" value= "GD"/&GT;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= "Pushbutton One"/>
<input type= "button" id= "JJ" value= "button two"/>
<br/>

<div id= "SSD" >fgfooHello</div>

</body>

<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=34]"). attr ("Checked", ' checked ');//value=34 Radio is selected

Alert ($ ("input[type=checkbox] [VALUE=GD]"). attr ("Checked", ' checked '));//value=gd checkbox selected
$ (' input[name=ff] '). Get (1). checked = true;//The first check is selected



/*//SELECT option 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 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); */



});
});
-
</script>

jquery operation input

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.