Jquery中css的回调函数中的index参数是什么意思?

查看:104
本文介绍了Jquery中css的回调函数中的index参数是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问 题

如下代码,index的值输出是0

<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>test</title>
<link rel="stylesheet" href="style.css"  />
<script src="http://libs.baidu.com/jquery/1.9.1/jquery.js"></script>
<style type="text/css">
    p{
        height: 100px;
        width: 80px;
    }
</style>
</head>
<body>
    <div>
        <p><span>123</span></p>
    </div>
<script>
    $("p").css("width",function(index,value){
        console.log(index,value);    //index值为0,不知道什么意思
    })
</script>
</body>
</html>

解决方案

<style type="text/css">
p{
    height: 100px;
    width: 80px;
}
p ~ p {
    width: 100px;
}
</style>
<div>
    <p><span>123</span></p>
    <p><span>123</span></p>
</div>

代码稍改一下你就能明白了

$('xxxx')返回的是一个元素集合,一种类似数组的结构(但不是数组),这index就相当于数组里的index
可以看下这里:http://www.css88.com/jqapi-1....

这篇关于Jquery中css的回调函数中的index参数是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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