<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.0/jquery.min.js"></script>
</head>
<body>
<?phpfor($i=0;$i<5;$i++){
?>
<p>xxxxxx</p>
<span id="x">
<?=$i?>
</span> <span id="show"><a href="#">获取id</a></span>
<?
}
?>
<script>
$("#show").click(function(){
var n=$("#x").html();
alert(n);
})
</script>
</body>
</html>问题:只能获取第一条id 后面的都获取不到 求解?
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.0/jquery.min.js"></script>
</head>
<body>
<?phpfor($i=0;$i<5;$i++){
?>
<p>xxxxxx</p>
<span id="x">
<?=$i?>
</span> <span id="show"><a href="#">获取id</a></span>
<?
}
?>
<script>
$("#show").click(function(){
var n=$("#x").html();
alert(n);
})
</script>
</body>
</html>问题:只能获取第一条id 后面的都获取不到 求解?
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.0/jquery.min.js"></script>
</head>
<body>
<?phpfor($i=0;$i<5;$i++){
?>
<p>xxxxxx</p>
<span class="x<?=$i?>">
<?=$i?>
</span> <span class="show" id="x<?=$i?>"><a href="#">获取id</a></span>
<?
}
?>
<script>
$(".show").click(function(){
var n=$("."+this.id).html();
alert(n);
})
</script>
</body>
</html>
<? echo $i?>
这一段不太好理解 刚开始我就意识到要用this这个关键字 一般重复的要取到当前值必用this或$(this) 但我就是不知道怎么用