jQuery framework for acquisition and setting radio button, check box, text box contents

Obtaining a set of radio selected value of the item
var item = $ ( "input [ name = 'items']: checked") val ();.
Gets select the selected item text
var item = $ (' # select_id option: selected ') .text ()
sELECT drop-down box of the currently selected element of the second value
$ (' # select_id ') [ 0] .selectedIndex = 1;
the second element radio radio group for the currently selected value of
$ ( "input [name = 'items'] " ) get (1) .checked = true.;

Get the value:

Text boxes, text areas: $ ( "# txt") attr ( "value");.
Checkbox checkbox: $ ( "# checkbox_id" ) attr ( "value");.
Radio Group radio: $ ( "input [type = 'radio']: checked ") val ();.
dropdown select: $ ( '# sel' ) val ();.

Control form elements:
text boxes, text areas: $ ( "# txt") attr ( "value", ''); // Clear contents.
$ ( "# TXT") attr ( "value",. '. 11') ; // filled with content

Checkbox checkbox: $ ( "# chk1" ) attr ( "checked", ''); // not tick.
$ ( "# Chk2") attr ( "the checked", to true); // tick.
IF if ($ ( "# chk1") . attr ( 'checked') == undefined) // judge has ticked

Radio Group radio: $ ( "input [type = 'radio']") attr ( "checked", '2'); // set value = 2 project for the currently selected item (wrong).
$ ( "The INPUT [ @ name = radio_s] [@ value = 16] ") attr (." checked ", true); ( test passed)

Drop-down box select: $ ( "# sel" ) attr ( "value", '- sel3'); // set value = project -sel3 selected item to the current.
$ ( "11,112,222") the appendTo ( "# SEL." ) // add a drop-down box in the Option
$ ( "# SEL") empty ();. // clear the drop-down box

$ ( "# select1") [ 0] .options (index) .selected = true; // index of the first option select th
   $ ( "# select1") [ 0] .options (3) .text // index is taken option value 3


This article comes from CSDN blog, reproduced, please indicate the source: http://blog.csdn.net/carefree31441/archive/2009/12/30/5100083.aspx

Published 16 original articles · won praise 1 · views 30000 +

Guess you like

Origin blog.csdn.net/wvtjplh/article/details/5251940