Select the relevant attributes for jQuery

2010-11-27  来源:本站原创  分类:Web  人气:149 

Select the relevant attributes for jQuery
2010-06-20 18:07
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

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 tick
$ ("# Chk2"). Attr ("checked", true); / / check
if ($("# chk1 "). attr ('checked') == undefined) / / check to determine whether

Radio Group radio: $ ("input [@ type = radio]"). Attr ("checked", '2');// project set value = 2 selected items for the current drop-down box 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

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;
It can be seen to have @ the beginning of a property that followed.

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

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'> 1111 </ option> <optionvalue='2'> 2222 </ option>"). AppendTo ("# sel") / / add the option drop-down box
$ ("# Sel"). Empty ();// clear the drop-down box [b] [/ b]

相关文章
  • Select the relevant attributes for jQuery 2010-11-27

    Select the relevant attributes for jQuery 2010-06-20 18:07 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 (" o

  • Select the device to use jquery to explain 2010-11-16

    Select the device to use jquery jquery explain the selector is css3, and the combination of XPath, jQuery extract the best part of two query languages, combined to create the ultimate jquery expression query language. If you are very familiar with CS

  • jquery下拉select控件操作方法分享(jquery操作select) 2015-04-12

    这篇文章主要介绍了jquery下拉select控件操作方法分享(jquery操作select),需要的朋友可以参考下 JQuery获取和设置Select选项方法汇总如下: 代码: $("#select_id").change(function(){//code...}); //为Select添加事件,当选择其中一项时触发 var checkText=$("#select_id").find("option:selected").text(); /

  • JQuery-form select the relevant use of summary 2010-10-11

    onChange event of drop-down list select JQuery to achieve: JQuery: $(document).ready(function () { $("#selectMenu").bind("change", function () { if ($(this).val() == "pro1") { $("#pro1").slideDown(); $("#pro2&q

  • Select the checkbox value judgments JQuery checkbox to determine whether the selected changes. Get value value 2011-05-12

    <html> <head> <script type="text/javascript" src="jquery-1.6.js"> </ script> <script type="text/javascript"> / / Get the value checkbox selected and assigned text box values function createOrder

  • 删除select中所有option选项jquery代码 2013-12-05

    select中所有option选项如何删除,本文使用jquery简单实现下,有此需求的朋友可以参考下,希望对大家有所帮助 这样写 <select id="search"> <option>baidu</option> <option>sogou</option> </select> 清空: 复制代码 代码如下: $("#search").find("option").remo

  • JS select the relevant drop-down box method 2009-09-01

    1. The dynamic creation of select function createSelect(){ var mySelect = document.createElement(select); mySelect.id = mySelect; document.body.appendChild(mySelect); } 2. Add Options option function addOption(){ According to ID lookup object, var ob

  • JS select the relevant methods of operation: Add Modify Delete selected to determine the existence of such empty 2011-08-15

    1 to determine whether there select option Value = "paraValue" of Item 2 to select option to add an Item 3 from the select option to delete an Item 4. Modify select option value = "paraValue" the text as "paraText" 5 Set sele

  • Classification of common database, select the relevant Certificate 2011-10-22

    The current mainstream databases including: Microsoft: sql server and access AB, Sweden: mysql IBM Corporation: db2 IBM Corporation: informix U.S. companies sybase: sybase U.S. orcale Company: orcale The choice of the actual project in the database:

  • Select the value obtained using JQuery 2010-12-10

    Radio $('#selectList').val(); $('#selectList').text(); Multiple choice var foo = []; $('#multiple :selected').each(function(i, selected){ foo[i] = $(selected).text(); });

  • Laopei help select box on Jquery operation of small practice 2010-07-13

    <% @ Page language = "java" import = "java.util .*" pageEncoding = "UTF-8"%> <% String path = request.getContextPath (); String basePath = request.getScheme () + "://" + Request.getServerName () + ":&q

  • jquery drop-down box to select a variety of operating methods (select, value, assignment, etc.) 2010-10-19

    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 on the radio, checkbox, select the related operations 2010-11-17

    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 ("

  • Select an action Jquery plugin js 2010-11-17

    jQuery.fn.size = function() { return jQuery(this).get(0).options.length; } // Get index of selected item jQuery.fn.getSelectedIndex = function() { return jQuery(this).get(0).selectedIndex; } // Access to the text of the currently selected item jQuery

  • Jquery for select, dropdownlist, checkbox value of the drop-down list box 2011-01-10

    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 ("

  • 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操作select方法汇总 2013-10-05

    这篇文章主要介绍了jquery操作select方法,实例汇总了jQuery操作select的读取.设置.添加及删除等技巧,需要的朋友可以参考下 本文实例汇总了jquery操作select的方法.分享给大家供大家参考.具体如下: jQuery获取Select选择的Text和Value: 语法解释: $("#select_id").change(function(){//code...});//为Select添加事件,当选择其中一项时触发 var checkText=$("#se

  • jQuery select操作控制方法小结 2013-10-18

    很多朋友对jquery select的操作很有兴趣,但网上的东西太多,所以脚本之家特别将Jquery Select操作方法整理下,方便大家查找. 需要注意的是,这里的代码好多是针对jquery 1.32以前的版本(以后的版本已经不支持@),所以替换为空测试下即可. jQuery获取Select选择的Text和Value: 语法解释: 1. $("#select_id").change(function(){//code...}); //为Select添加事件,当选择其中一项时触发 2.

  • JS,Jquery获取select,dropdownlist,checkbox下拉列表框的值(示例代码) 2014-02-06

    本篇文章主要是对JS,Jquery获取select,dropdownlist,checkbox下拉列表框的值(示例代码)进行了介绍,需要的朋友可以过来参考下,希望对大家有所帮助 jQuery获取Select选择的Text和Value: 语法解释: 1. $("#select_id").change(function(){//code...}); //为Select添加事件,当选择其中一项时触发 2. var checkText=$("#select_id").fin

  • JQuery给元素添加/删除节点比如select 2014-02-07

    本教程详细介绍下jQuery添加/删除Select的Option项,感兴趣的各位可以参考下哈 jQuery获取Select选择的Text和Value: var checkText=jQuery("#select_id").find("option:selected").text(); //获取Select选择的Text var checkValue=jQuery("#select_id").val(); //获取Select选择的option V