.get(index) and .eq(index)

  • both return a single "element" from a jQuery object array, but they return the single element in different forms.

.eq(index)

  • returns it as a jQuery object, meaning the DOM element is wrapped in the jQuery wrapper, which means that it accepts jQuery functions.

.get(index)

  • return a raw DOM element. You may manipulate it by accessing its attributes and invoking its functions as you would on a raw DOM element. But it loses its identity as a jQuery-wrapped object, so a jQuery function won't work.

简言之:eq()获取的是jquery对象,能够使用jquery方法,get()获取的是原生dom元素,不能使用jquery方法.

Example:

 <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>eq() And get()</title>
</head>
<body style="height:2000px;">
<script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
<div id="outer_div">
<div>
<input text value="AAA"><br>
<input text value="BBB"><br>
<input text value="CCC"><br>
<input text value="DDD"><br>
</div>
</div>
<script>
$(document).ready(function(){
var $inputEq = $('#outer_div').find("input").eq(2);
var $inputGet = $('#outer_div').find("input").get(2);
console.log("inputEq :"+$inputEq);
console.log("inputGet:"+$inputGet);
console.log("inputEqValue :"+$inputEq.val());
console.log("inputGetValue :"+$inputGet.value);
});
// Results:
/*
inputEq :[object Object]
inputGet:[object HTMLInputElement]
inputEqValue :CCC
inputGetValue :CCC
*/
</script>
</body>
</html>

相关:

.eq()

  • .eq( index )
  • .eq( indexFromEnd )
<ul>
<li>list item 1</li>
<li>list item 2</li>
<li>list item 3</li>
<li>list item 4</li>
<li>list item 5</li>
</ul>
$( "li" ).eq( 2 ).css( "background-color", "red" );
$( "li" ).eq( -2 ).css( "background-color", "blue" );

:eq() Selector

  • jQuery( ":eq(index)" )
  • jQuery( ":eq(-index)" )

.get()

  • .get( index )
 <ul>
<li id="foo">foo</li>
<li id="bar">bar</li>
</ul>
console.log( $( "li" ).get( 0 ) );
  • .get()
  1. Retrieve the elements matched by the jQuery object.
  2. All of the matched DOM nodes are returned by this call, contained in a standard array.
 <ul>
<li id="foo">foo</li>
<li id="bar">bar</li>
</ul>
// javascript
console.log( $( "li" ).get() );
// result
[<li id="foo">, <li id="bar">]

jQuery : eq() vs get()的更多相关文章

  1. jquery eq()选择器 语法

    jquery eq()选择器 语法 作用::eq() 选择器选取带有指定 index 值的元素.index 值从 0 开始,所有第一个元素的 index 值是 0(不是 1).经常与其他元素/选择器一 ...

  2. jQuery.eq() 函数

    eq() 函数 获取当前对象中指定索引所对应的的元素 语法 $selector.eq(index)//index为指定索引,值为数字型 返回值 返回值为一个对象 实例说明 代码 <!DOCTYP ...

  3. jquery eq 用法

    <html> <head> <script src='jquery.min.js'></script> <script type="te ...

  4. CSS中:nth-child和JQuery:eq的区别

    $("li:nth-child(n)")选择器与$("li:eq(n)")选择器的不同之处在于:$("li:eq(n)")选择器只匹配一个元 ...

  5. jQuery遍历 - 过滤first(),last()和eq()使用

    jQuery遍历 - 过滤最基本的过滤方法是first(),last()和eq(),它们允许您根据元素在一组元素中的位置选择特定元素. 其他过滤方法(如filter()和not())允许您选择与特定条 ...

  6. 浅谈我对 jQuery 的了解

    总述 0 获取 jQuery 对象 1 对象跳转 2 方法调用 3 常用API 4 $(…); 5 jQuery 对象获取 6 Data 相关方法 7 选择器 8 基本的过滤器 9 内容过滤选择器 1 ...

  7. jQuery用法小结

    jQuery加载1.$(document).ready()2.添加css样式:单个:$("p").css("color","red"); 多 ...

  8. jQuery中的end()

    要说end(),我们就不得不说prevObject. 在jQuery中,每个jQuery对象都有一个prevObject属性 var $p = $('p'); 这个属性是做什么的呢? jQuery内部 ...

  9. jquery 之选择器

    一.基本: HTML代码: <p class="p1">p段落</p> <h class="h1">h标签</h> ...

随机推荐

  1. Hadoop.2.x_无秘钥设置

    1.在实际生产环境中为Hadoop配置无秘钥登录非常有必要 # 在没有配置时: [liuwl@linux-66-64 hadoop-2.5.0]$ jps 26163 Jps [liuwl@linux ...

  2. ArcGIS AddIN开发之自定义鼠标样式

    如果想修改Windows默认的鼠标样式,可以这样 //设置鼠标样式 this.Cursor = System.Windows.Forms.Cursors.Cross; 可是如果想设置成一些自定义的很好 ...

  3. 手机触屏触摸特效javascript-TouchSwipe(依赖于jquery库)中文说明

    by 郑州seo on 2013 年 7 月 6 日 in jquery, 网站建设 with 6 Comments 最近需要做一个手机小门户网站,因为目前主流的手机都是安卓和苹果的,他们的浏览器内核 ...

  4. jenkins使用deploy-plugin自动构建部署war包

    jenkins+ant+maven+tomcat 1安装 jenkins 使用yum安装的 # 下载库 wget -O /etc/yum.repos.d/jenkins.repo http://pkg ...

  5. iOS 导入第三方文件夹时右侧出现问号

    首先,和版本库有关. a代表add,m代表modify,?代表未能识别,通常如果使用git之类的版本控制器,添加文件后没有进行提交,就会出现? 1.遇到引用文件夹为蓝色的情况,是你以为勾了copy项, ...

  6. iOS9 HTTP传输安全

    1.在Info.plist中添加 NSAppTransportSecurity 类型  Dictionary 2.在 NSAppTransportSecurity 下添加 NSAllowsArbitr ...

  7. 关于Java擦除特性

    package thinkingInJava; /* * 模拟擦除 */ public class SimpleHolder { private Object obj ; public void se ...

  8. 《UML大战需求分析》阅读笔记02

    软件应能真正的对客户的工作提供帮助,只有客户使用并真正对其有用才能说我们做的软件成功了.客户从开始提出需求时到后期的工作过程中,需求总是不停变化的,所以这就需要需求人员对需求领先于客户.所以活用UML ...

  9. C#编程利器之三:接口(Interface)【转】

    C#编程利器之三:接口(Interface) C#接口是一个让很多初学者容易迷糊的东西,用起来好象很简单,定义接口,然后在里面定义方法,通过继承与他的子类来完成具体的实现.但没有真正认识接口的作用的时 ...

  10. transform的用法和注意事项

    1.作用: 1)transform可以控制平移.比例缩放和旋转. 2)transform中的方法主要分为两种:带make和不带make的方法. 3)带make的方法主要是基于控件最初的状态进行改变,所 ...