当前位置: 代码迷 >> Web前端 >> jquery失去div的id值
  详细解决方案

jquery失去div的id值

热度:81   发布时间:2012-09-27 11:11:17.0
jquery得到div的id值
<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)是取第一个jq元素。。。

?

eq(index)
匹配一个给定索引值的元素

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

Matches a single element by its index.
返回值
Element

参数
index (Number) : 从 0 开始计数

示例
查找第二行

HTML 代码:

<table>
<tr><td>Header 1</td></tr>
<tr><td>Value 1</td></tr>
<tr><td>Value 2</td></tr>
</table>
jQuery 代码:

$("tr:eq(1)")
结果:
[ <tr><td>Value 1</td></tr> ]

  相关解决方案