jQuery对象使用

jQuery对象是一个包含所有匹配的任意多个dom元素的为数组对象
基本行为:

  1. length:包含的dom元素个数
  2. [index]/get(index):得到对应位置的DOM元素
  3. each():遍历包含的所有DOM元素
  4. index():得到在所有兄弟元素中的下标
    用法如下:
<script type="text/javascript" src="../js/jquery-3.1.1/jquery-3.1.1.min.js"></script>
		<script type="text/javascript">
			$(function(){
				//统计一共有多少个按钮
			console.log($('button').length);

			//取出第二个button的文本
		
			console.log($('button')[1].innerHTML);
			console.log($('button').get(1).innerHTML);
			//输出所有button标签的文本
			$('button').each(function(){
				console.log(this.innerHTML);
				//console.log($(this).html());
			});
			$('button').each(function(index,domEle){
				//console.log(this.innerHTML);
				//console.log($(this).html());
				console.log(index,domEle.innerHTML);
			});
			//输出测试三按钮是所有按钮中的第几个
			console.log($('#btn3').index()+1);
			});
			/*伪数组
			 * Object对象
			 * length属性
			 * 数组下标属性
			 * 上面的button就是伪数组
			 */
		</script>
	</head>
	<body>
		<button>测试一</button>
		<button>测试二</button>
		<button id="btn3">测试三</button>
		<button>测试四</button>
	</body>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值