先看看托图片:
紧接着就是代码了:
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title></title>
<script src="jquery.js"></script>
<style>
p{
width: 200px;
height: 50px;
background-color: aqua;
}
</style>
</head>
<body>
<center>
<h2>点击当前的p标签,弹出相对应的元素下标</h2>
<p>1</p>
<p>2</p>
<p>3</p>
<p>4</p>
</center>
<script>
$(function () {
$("p").click(function () {
alert($(this).index())
})
});
</script>
</body>
</html>