jquery – 如何获取eq()值?

前端之家收集整理的这篇文章主要介绍了jquery – 如何获取eq()值?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
这可能吗?为了得到eq()值?例如,如果我单击li:eq(2),var x将变为2.这是代码.
$('#numbers ul li').click(function(){
  x=$(this).eq().val();
  alert(x);
});
@H_301_5@解决方法
.index() what is this?方法会这样做.
$('#numbers ul li').click(function() {
  var self   = $(this),index  = self.index(),text   = self.text();

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

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

原文链接:https://www.f2er.com/jquery/180421.html

猜你在找的jQuery相关文章