日期:2014-05-16 浏览次数:20436 次
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.7.2.min.js"></script>
<script>
$(function(){
$('.text a').click(function(){
var curDiv=$(this).parent();
alert('当前的div ID为:'+curDiv.attr("id")+',索引为:'+curDiv.index());
});
})
</script>
</head>
<body>
<div class="text" id="div1">
<a href="#">测试1</a>
</div>
<div class="text" id="div2">
<a href="#">测试2</a>
</div>
<div class="text" id="div3">
<a href="#">测试3</a>
</div>
</body>
</html>