如何获得eq()值? [英] How to get the eq() value?

查看:92
本文介绍了如何获得eq()值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这可能吗?对我来说,获得eq()值?例如,如果单击li:eq(2),则var x将变为2.这是代码.

Is this possible? For me to get the eq() value? For example, if I click the li:eq(2), var x will become 2. Here's the code.

$('#numbers ul li').click(function(){
  x=$(this).eq().val();
  alert(x);
});

推荐答案

.index() 这是什么? 方法即可.

The .index()what is this? method will do it.

$('#numbers ul li').click(function() {
  var self   = $(this),
      index  = self.index(),
      text   = self.text();

  alert(text + ' ' + index);
});

演示: http://www.jsfiddle.net/Y2aDP/

这篇关于如何获得eq()值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆