common method of operation input.select.checkbox.radio jquery

2011-05-24  来源:本站原创  分类:Web  人气:163 

jQuery get select Select Text and Value:
Syntax explanation:
1. $ ("# Select_id"). Change (function (){// code ...}); / / add an event for the Select, when you select one of the trigger
2. Var checkText =$("# select_id "). Find (" option: selected "). Text (); / / Get the selected Text Select
3. Var checkValue =$("# select_id "). Val (); / / Get the selected Value Select
4. Var checkIndex =$("# select_id "). Get (0). SelectedIndex; / / get selected index value Select
5. Var maxIndex =$("# select_id option: last "). Attr (" index "); / / Select the maximum index value for
jQuery select Text and set the Select Value:
Syntax explanation:
1. $ ("# Select_id"). Get (0). SelectedIndex = 1; / / set the index value of 1 Select the items selected
2. $ ("# Select_id"). Val (4); / / Set the Value Select an item is selected 4
3. $ ("# Select_id option [text = 'jQuery']"). attr (" selected ", true); / / Set the Text Select an item is selected jQuery

jQuery Add / Remove Select the Option key:
Syntax explanation:
1. $ ("# Select_id"). Append ("<option value='Value'> Text </ option>"); / / append to Select an Option (the drop-down items)
2. $ ("# Select_id"). Prepend ("<option value='0'> Select </ option>"); / / to insert a Select Option (first position)
3. $ ("# Select_id option: last"). Remove (); / / Remove Select the largest index value in the Option (the last one)
4. $ ("# Select_id option [index = '0']"). remove (); / / Remove the index value of 0 Select Option (first)
5. $ ("# Select_id option [value = '3']"). remove (); / / Remove Select the Value = '3 'of the Option
5. $ ("# Select_id option [text = '4']"). remove (); / / Remove Select the Text = '4 'of the Option

http://www.cnblogs.com/SAL2928/archive/2008/10/28/1321285.html

jquery radio value, checkbox values, select values, radio check, checkbox is selected, select selected, and its associated radio access to a group of the value of the selected items
var item = $ ('input [name = items] [checked]'). val ();
Get select the text of the selected items
var item = $ ("select [name = items] option [selected]"). text ();
drop-down box to select the second element of value for the currently selected
$ ('# Select_id') [0]. SelectedIndex = 1;
radio radio group, select the second element is the current value
$ ('Input [name = items]'). Get (1). Checked = true;
Get value:
Text box, text area :$("# txt "). Attr (" value ");
Checkbox checkbox :$("# checkbox_id "). Attr (" value ");
Radio Group radio: $ ("input [type = radio] [checked]"). Val ();
Drop-down box select: $ ('# sel'). Val ();
Control of form elements:
Text box, text area :$("# txt "). Attr (" value ",'');// empty content
$ ("# Txt"). Attr ("value", '11');// padding checkbox checkbox: $ ("# chk1"). Attr ("checked ",'');// not fight hook
$ ("# Chk2"). Attr ("checked", true); / / check
if ($("# chk1 "). attr ('checked') == undefined) / / check to determine whether the radio group radio: $ (" input [type = radio] "). attr (" checked ", '2');// project set value = 2 drop-down box for the currently selected item select: $ ("# sel"). attr ("value", '-sel3');// set value =- sel3 project for the currently selected item
$ ("<option Value='1'> 1111 </ option> <option value='2'> 2222 </ option>"). AppendTo ("# sel") / / add the option drop-down box
$ ("# Sel"). Empty ();// clear the drop-down box

-------------------------------------------------- --------------------------------------------------

/ / Traverse the option and add and remove option
function changeShipMethod (shipping) {
var len = $ ("select [name = ISHIPTYPE] option"). length
if (shipping.value! = "CA") {
$ ("Select [name = ISHIPTYPE] option"). Each (function () {
if ($ (this). val () == 111) {
$ (This). Remove ();
}
});
} Else {
$ ("<option Value='111'> UPS Ground </ option>"). AppendTo ($ ("select [name = ISHIPTYPE ]"));
}
}

/ / Get the value of the drop-down menu select

$ (# TestSelect option: selected '). Text ();
Or $ ("# testSelect"). Find ('option: selected'). Text ();
Or $ ("# testSelect"). Val ();
////////////////////////////////////////////////// ////////////////
Bad memory can collect under:
1, the drop-down box:

var cc1 = $ (". formc select [name = 'country'] option [selected]"). text (); / / get the drop-down menu select the item text (note the spaces in the middle)
var cc2 = $ ('. formc select [name = "country "]'). val (); / / get the drop-down menu select the value of items
var cc3 = $ ('. formc select [name = "country "]'). attr (" id "); / / get the drop-down menu select the item ID attribute value
$ ("# Select"). Empty ();// clear the drop-down box //$("# select "). Html ('');
$ ("<option Value='1'> 1111 </ option>"). AppendTo ("# select") / / add the option drop-down box

Explain a little:
1.select [name = 'country'] option [selected] that has the name attribute,
And the property value of 'country' of the select element inside the element with the selected option attribute;

2, a single box:
$ ("Input [@ type = radio] [@ checked]"). Val (); / / get the selected radio button item value (note no spaces)
$ ("Input [@ type = radio] [@ value = 2]"). Attr ("checked", 'checked'); / / set radio button value = 2 for the selected state. (Note that there is no space between cell)

3 check boxes:
$ ("Input [@ type = checkbox] [@ checked]"). Val (); / / get the first check box value selected
$ ("Input [@ type = checkbox] [@ checked]"). Each (function () {/ / the check box is selected more than normal, so the output can be recycled
alert ($ (this). val ());
});

$ ("# Chk1"). Attr ("checked ",'');// not tick
$ ("# Chk2"). Attr ("checked", true); / / check
if ($("# chk1 "). attr ('checked') == undefined) {} ​​/ / check to determine whether

Of course jquery selector is strong. There are many methods.

<script src="jquery-1.2.1.js" type="text/javascript"> </ script>
<script language="javascript" type="text/javascript">
$ (Document). Ready (function () {
$ ("# SelectTest"). Change (function ()
{
/ / Alert ("Hello");
/ / Alert ($("# selectTest "). Attr (" name "));
//$(" A "). Attr (" href "," xx.html ");
/ / Window.location.href = "xx.html";
/ / Alert ($("# selectTest "). Val ());
alert ($("# selectTest option [@ selected] "). text ());
$ ("# SelectTest"). Attr ("value", "2");

});
});
</ Script>

<a href="#"> aaass </ a>

<! - Drop-down box ->
<select name="selectTest">
<option value="1"> 11 </ option>
<option value="2"> 22 </ option>
<option value="3"> 33 </ option>
<option value="4"> 44 </ option>
<option value="5"> 55 </ option>
<option value="6"> 66 </ option>
</ Select>
jquery radio value, checkbox values, select values, radio check, checkbox is selected, select selected, and its associated radio access to a group of the value of the selected items
var item = $ ('input [@ name = items] [@ checked]'). val ();
Get select the text of the selected items
var item = $ ("select [@ name = items] option [@ selected]"). text ();
drop-down box to select the second element of value for the currently selected
$ ('# Select_id') [0]. SelectedIndex = 1;
radio radio group, select the second element is the current value
$ ('Input [@ name = items]'). Get (1). Checked = true;
Get value:
Text box, text area :$("# txt "). Attr (" value ");
Checkbox checkbox :$("# checkbox_id "). Attr (" value ");
Radio Group radio: $ ("input [@ type = radio] [@ checked]"). Val ();
Drop-down box select: $ ('# sel'). Val ();
Control of form elements:
Text box, text area :$("# txt "). Attr (" value ",'');// empty content
$ ("# Txt"). Attr ("value", '11');// padding checkbox checkbox: $ ("# chk1"). Attr ("checked ",'');// not fight hook
$ ("# Chk2"). Attr ("checked", true); / / check
if ($("# chk1 "). attr ('checked') == undefined) / / check to determine whether the radio group radio: $ (" input [@ type = radio] "). attr (" checked " , '2');// project set value = 2 drop-down box for the currently selected item select: $ ("# sel"). attr ("value", '-sel3');// set value =- sel3 project for the currently selected item
$ ("<Optionvalue = '1 '& gt; 1111 </ option> <optionvalue='2'> 2222 </ option & gt;"). AppendTo ("# sel") / / add the option drop-down box
$ ("# Sel"). Empty ();// clear the drop-down box

Get a group of radio is the value of the selected item
var item = $ ('input [@ name = items] [@ checked]'). val ();
Get select the text of the selected items
var item = $ ("select [@ name = items] option [@ selected]"). text ();
drop-down box to select the second element of value for the currently selected
$ ('# Select_id') [0]. SelectedIndex = 1;
radio radio group, select the second element is the current value
$ ('Input [@ name = items]'). Get (1). Checked = true;
Get value:
Text box, text area :$("# txt "). Attr (" value ");
Checkbox checkbox :$("# checkbox_id "). Attr (" value ");
Radio Group radio: $ ("input [@ type = radio] [@ checked]"). Val ();
Drop-down box select: $ ('# sel'). Val ();
Control of form elements:
Text box, text area :$("# txt "). Attr (" value ",'');// empty content
$ ("# Txt"). Attr ("value", '11');// padding checkbox checkbox: $ ("# chk1"). Attr ("checked ",'');// not fight hook
$ ("# Chk2"). Attr ("checked", true); / / check
if ($("# chk1 "). attr ('checked') == undefined) / / check to determine whether the radio group radio: $ (" input [@ type = radio] "). attr (" checked " , '2');// project set value = 2 drop-down box for the currently selected item select: $ ("# sel"). attr ("value", '-sel3');// set value =- sel3 project for the currently selected item
$ ("<option Value='1'> 1111 </ option> <option value='2'> 2222 </ option>"). AppendTo ("# sel") / / add the option drop-down box
$ ("# Sel"). Empty ();// clear the drop-down box

相关文章
  • common method of operation input.select.checkbox.radio jquery 2011-05-24

    jQuery get select Select Text and Value: Syntax explanation: 1. $ ("# Select_id"). Change (function (){// code ...}); / / add an event for the Select, when you select one of the trigger 2. Var checkText =$("# select_id "). Find ("

  • jQuery操作form input.select.checkbox.radio常用方法 2014-11-13

    jQuery获取Select选择的Text和Value: 语法解释: 1. $("#select_id").change(function(){//code...}); //为Select添加事件,当选择其中一项时触发 2. var checkText=$("#select_id").find("option:selected").text(); //获取Select选择的Text 3. var checkValue=$("#selec

  • JS operations and firefox Xiangjie select the method of operation of select 2010-04-19

    Javascript operation select Control Daquan javascript get select the value of the whole solution Is the basis of the above two operations with the js link to select the article. Firefox recently encountered in the development of operating in select a

  • common method of operation python file 2010-06-05

    python file operations are very convenient, it has many ways to make the file operation is very simple, short, under the following python how to operate the file. Open the file: Can open method and file method. Parameters to distinguish between the b

  • Common method of operation of Excel 2010-10-23

    using System; using System.Collections.Generic; using System.Text; using Excel = Microsoft.Office.Interop.Excel; using System.Diagnostics; using System.Windows.Forms; namespace OfficeManager { public class ExcelClass : IDisposable { private Excel._Ap

  • js operation checkbox, radio, select 2010-09-08

    JS recently often operate select checkbox and radio recording function following a few simple to use for future reference Js code function getRadioValue (radioName) ( var obj = document.getElementsByName (radioName); var objLen = obj.length; var i; f

  • jQuery根据ID获取input.checkbox.radio.select的示例 2014-07-26

    获取input.checkbox.radio.select的方法有很多,下面本例为大家介绍下根据ID来获取 input: var xxx = $('#ID').val() --------------------------------------------------------------------------------- checkbox: var xxx = [ ]; $('input[name=MyName]:checked).each(function(index, eleme

  • js select checkbox and radio operation 2010-12-10

    JS operating select checkbox and radio recording function following a few simple function getRadioValue(radioName){ var obj = document.getElementsByName(radioName); var objLen= obj.length; var i; for (i = 0;i< objLen;i++){ if (obj [i].checked==true)

  • JQuery operation checkbox.radio 2010-04-14

    JQuery operation checkbox, radio Radio is selected for a group of key values var type = $ ('input [@ name = type] [@ checked]'). val (); var usable = $ ('input [@ name = usable] [@ checked]'). val () Access to select the text of the selected items va

  • LazyForm jQuery plugin 定制您的CheckBox Radio和Select 2015-03-01

    LazyForm jQuery plugin 定制您的CheckBox Radio和Select ,需要的朋友可以参考下. 在下面浏览器下测试通过:Firefox, IE7, IE8, Google浏览器. (IE6还是算了吧),其它浏览器还没试过. 目前刚添加了4个皮肤,添加新皮肤非常方便,您可以参考已添加的皮肤图片和css代码,相信您会很快搞定. 效果截图: 一.在没有使用LazyForm的情况下,在XP下运行截图如下 二.使用LazyForm(皮肤Blue)效果如下 三.使用LazyFor

  • jquery select values, radio value, checkbox Value, radio selected 2010-08-09

    Jquery on the Radio, checkbox, select the following: jquery radio value, checkbox values, select values, radio check, var item = $('input[@name=items][@checked]').val(); Access to select the text of the selected items var item = $("select[@name=items

  • jquery radio value, checkbox values, select values, radio check, checkbox is selected, select selected, and its related 2010-11-02

    Under the version of jQuery 1.3.2 jquery radio value, checkbox values, select values, radio check, checkbox is selected, select selected, and its related Set Radio is selected for a group of key values: var item = $ ('input [name = items] [checked]')

  • Jquery 操作Html 控件 CheckBox.Radio.Select 控件 2014-06-22

    在使用 Javascript 编写前台脚本的时候,经常会操作 Html 控件,比如 checkbox.radio.select,用 Jquery 库操作其他会方便很多,下面用Jq对这些控件的操作进行一个全面的代码总结. 一.Jquery 对 CheckBox 的操作: <input id="ckb1" name="ckb" checked="checked" value="0" type="checkbox&q

  • 关于表单的组件 radio select checkbox 2014-09-21

    搞了几天的页面发现一些表单组件的细节问题,确实是要命啊 1)checkbox 在火狐浏览器中是无法调整大小的,但在其他浏览器中则可以调整,有时为了满足浏览器的兼容性,我想我应该首先放弃的就是checkbox,可以采用图片进行应对,因此,采用<img>替代<input type='checkbox'> 2)不仅仅是checkbox那么烦人,实际上<select>同样招人讨厌,为什么呢,其一他的大小在某些浏览器中是无法设置的,至少我在手机上就是遇到这样的问题,其二,他的背景

  • Jquery operation of the checkbox, select all, values 2011-01-14

    <! DOCTYPE HTML PUBLIC "- / / W3C / / DTD HTML 4.0 Transitional / / EN"> <HTML> <HEAD> <TITLE> New Document </ TITLE> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> &

  • List of common method jQuery 2010-10-25

    List of common method jQuery Attribute: $ ("P"). AddClass (css style defined type); to add an element of style $ ("Img"). Attr ({src: "test.jpg", alt: "test Image"}); to add an element, attribute / value parameter i

  • JQuery tutorial basic common method 2009-06-02

    $ ( "P"). AddClass (css style defined type); to add an element of style $ ( "Img"). Attr ((src: "test.jpg", alt: "test Image")); to add an element property / value parameter is the map $ ( "Img"). Attr ( &

  • JQuery common method Essentials 2010-04-28

    Attribute: $ ("P"). AddClass (css style defined type); to add an element of style $ ("Img"). Attr ((src: "test.jpg", alt: "test Image")); to add an element, attribute / value, the parameter is the map $ ("Img&q

  • JQuery common method of collection 2010-07-02

    Attribute: $ ("P"). AddClass (css style defined type); to add an element of style $ ("Img"). Attr ((src: "test.jpg", alt: "test Image")); to add an element, attribute / value, the parameter is the map $ ("Img&q

  • Linux common method of software installation (Reprinted) 2010-05-10

    1, uninstall the software installation, sub-situations: A: RPM package, this package like the windows of the EXE installation file, as all documents have been compiled and patched, which documents the folder into which all the designated well, instal