今天在群里聊天,有个骚年提了一个问题,对w3cschool上的一个click时间的示例demo不解,我自己去看了下,发现也不懂,就是里面函数的参数问题,先贴代码。
<html>
<head>
<script src="//cdn.bootcss.com/jquery/2.1.4/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function () {
$("div").click(function () {
$(this).css(
"width",
function (index, value) {
return parseFloat(value) * 1.2;
}
);
});
});
</script>
<style>
div {
width: 100px;
height: 50px;
background-color: red;
}
</style>
</head>
<body>
<div>请点击这里</div>
</body>
</html>
我的疑问是:这里的index
参数有什么作用?index
和value
的值是哪里来的?如果我去掉index
,后面的value
就会取不到值,为什么?
http://api.jquery.com/css/#css-propertyName-function