How to get ID value in jquery summary _jquery

Source: Internet
Author: User

Copy Code code as follows:

<div id= "Product_shift_out_{m}" > </div>
<script language = "JavaScript" type= "Text/javascript" >
$ (document). Ready (function () {
Name = $ (' div '). EQ (0). attr (' id ');
Alert (name)
});
</script>

EQ (0) is to take the first JQ element ...

EQ (Index)
An element that matches a given index value

Matches a single element by its index.
return value
Element

Parameters
Index (number): Counting starting from 0

Example
Find second row

HTML Code:

Copy Code code as follows:

<table>
<tr><td>header 1</td></tr>
<tr><td>value 1</td></tr>
<tr><td>value 2</td></tr>
</table>

JQuery Code:

Copy Code code as follows:

$ ("Tr:eq (1)")

Results:

Copy Code code as follows:

[<tr><td>value 1</td></tr>]

Get values for different IDs

Copy Code code as follows:

<script src= "Js/jquery.js" ></script>
<script type= "Text/javascript" >
<!--
$ (document). Ready (function () {
var len = $ ("#group span"). Size ();//Get the number of span labels
var arr = [];
for (var index = 0; index < len-1; index++) {//Create a numeric array
Arr[index] = index;
}
$.each (arr, function (i) {//loop to get different ID values
var idvalue = $ ("#group span"). EQ (i). attr ("id");
if (idvalue!= ') {
alert (idvalue);
}
});
});
-->
</script>
<span id= "group" >
<span id= "0_1" >aaa,
<span group_id= "0_1" class= "Icon_close" > </span>
</span>
<span id= "0_2" >bbb,
<span group_id= "0_2" class= "Icon_close" > </span>
</span>
<span id= "0_3" &GT;CCC,
<span group_id= "0_3" class= "Icon_close" > </span>
</span>
<span id= "0_4" >ddd,
<span group_id= "0_4" class= "Icon_close" > </span>
</span>
<span id= "0_5" >eee,
<span group_id= "0_5" class= "Icon_close" > </span>
</span>
</span>

This will get all the IDs you want:
0_1
0_2
0_3
0_4
0_5

text box, text area:

Copy Code code as follows:

$ ("#txt"). attr ("Value", "");/empty content
$ ("#txt"). attr ("value", ' 11 ');//fill content

Multi-selection box checkbox:

Copy Code code as follows:

$ ("#chk1"). attr ("Checked", "");/no tick.
$ ("#chk2"). attr ("Checked", true);/tick
if ($ ("#chk1"). attr (' checked ') ==undefined)//judge whether it has been ticked

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.