jQuery : eq() vs get()
.get(index) and .eq(index)
- both return a single "element" from a jQuery object array, but they return the single element in different forms.
- returns it as a jQuery object, meaning the DOM element is wrapped in the jQuery wrapper, which means that it accepts jQuery functions.
- 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( 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" );
- jQuery( ":eq(index)" )
- jQuery( ":eq(-index)" )
- .get( index )
<ul>
<li id="foo">foo</li>
<li id="bar">bar</li>
</ul>
console.log( $( "li" ).get( 0 ) );
- .get()
- Retrieve the elements matched by the jQuery object.
- 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()的更多相关文章
- jquery eq()选择器 语法
jquery eq()选择器 语法 作用::eq() 选择器选取带有指定 index 值的元素.index 值从 0 开始,所有第一个元素的 index 值是 0(不是 1).经常与其他元素/选择器一 ...
- jQuery.eq() 函数
eq() 函数 获取当前对象中指定索引所对应的的元素 语法 $selector.eq(index)//index为指定索引,值为数字型 返回值 返回值为一个对象 实例说明 代码 <!DOCTYP ...
- jquery eq 用法
<html> <head> <script src='jquery.min.js'></script> <script type="te ...
- CSS中:nth-child和JQuery:eq的区别
$("li:nth-child(n)")选择器与$("li:eq(n)")选择器的不同之处在于:$("li:eq(n)")选择器只匹配一个元 ...
- jQuery遍历 - 过滤first(),last()和eq()使用
jQuery遍历 - 过滤最基本的过滤方法是first(),last()和eq(),它们允许您根据元素在一组元素中的位置选择特定元素. 其他过滤方法(如filter()和not())允许您选择与特定条 ...
- 浅谈我对 jQuery 的了解
总述 0 获取 jQuery 对象 1 对象跳转 2 方法调用 3 常用API 4 $(…); 5 jQuery 对象获取 6 Data 相关方法 7 选择器 8 基本的过滤器 9 内容过滤选择器 1 ...
- jQuery用法小结
jQuery加载1.$(document).ready()2.添加css样式:单个:$("p").css("color","red"); 多 ...
- jQuery中的end()
要说end(),我们就不得不说prevObject. 在jQuery中,每个jQuery对象都有一个prevObject属性 var $p = $('p'); 这个属性是做什么的呢? jQuery内部 ...
- jquery 之选择器
一.基本: HTML代码: <p class="p1">p段落</p> <h class="h1">h标签</h> ...
随机推荐
- vim 基础命令
第一部份:一般指令模式可用的按鈕說明,游標移動.複製貼上.搜尋取代等 移動游標的方法 h 或 向左方向鍵(←) 游標向左移動一個字元 j 或 向下方 ...
- Hibernate的一级二级缓存机制配置与测试
特别感谢http://www.cnblogs.com/xiaoluo501395377/p/3377604.html 在本篇随笔里将会分析一下hibernate的缓存机制,包括一级缓存(session ...
- mysql导数据库用到的语句
将字段格式为2013-08-09 13:22:55转换为时间戳 UPDATE `AttendClass` SET `regdate` = unix_timestamp(regDate2) WHERE ...
- SpringBoot实例
7player 7号球员 -- Show Time !跳至内容 首发 左边锋 技术流 外援 教练 7号 基于SpringBoot + Mybatis实现SpringMVC Web项目[原创] 目录 [ ...
- A+B Problem III-(涉及误差)NYOJ-477
描述求A+B是否与C相等. 输入 T组测试数据. 每组数据中有三个实数A,B,C(-10000.0<=A,B<=10000.0,-20000.0<=C<=20000.0) ...
- 重新启动 Apache 以加载上面安装的模块
尽管Ubuntu 是一种新兴的Linux分支,但Ubuntu 组织却为Apache提供了丰富的支持软件,这些软件都可以从发行版的光盘获取,也可以从官方站点轻松下载.所以,Ubuntu非常适合作为Web ...
- 【转】在sqlserver下增加MYSQL的链接服务器,实现分布式数据库开发第一步
首先要在SQLserver上服务器上这装ODBC对mysql的支持,我下载了mysql-connector-odbc-5.1.5-win32.rar,安装后在ODBC中有了DRIVER={MySQL ...
- windows查看端口命令
netstat -ano 查看所有端口 netstat -ano|findstr "1935" 查看1935端口占用PID tasklist|findstr "PID”
- 奥迪--A6L
-型号:A6L -价格:42-75W -动力:1.8T/2.5L/3T -变速箱:7挡双离合/CVT无级变速/7挡双离合 -长宽高:5.04,1.87,1.47 -油箱:75L -发动机:EA888 ...
- Thinking in Java——笔记(1)
Introduction To Obejct The progress of abstraction But their primary abstraction still requires you ...