<!DOCTYPE html>
<head>
<meta charset="UTF-8">
<title>Document</title>
<script type="text/javascript" src="../jquery-1.9.1.min.js"></script>
<script type="text/javascript">
$(function(){
$('table tr').click(function(){
$('table tr').removeClass('on')
$(this).addClass('on')
})
})
</script>
<style type="text/css">
*{
padding: 0
margin: 0
}
tr.on td{
background-color: #e5e5e5
}
</style>
</head>
<body>
<table width="100%">
<tr class="on">
<td>sdfas</td>
</tr>
<tr>
<td>sdfas</td>
</tr>
<tr>
<td>sdfas</td>
</tr>
<tr>
<td>sdfas</td>
</tr>
</table>
</body>
</html>
可以换个方式来实现,测试可行:
<!DOCTYPE html><html>
<head>
<title>demo</title>
<script src="http://libs.baidu.com/jquery/1.9.0/jquery.js"></script>
<script type="text/javascript">
$(function(){
$(".aa").click(function(){
var v = $(this).attr("value")
if(v == 1){
$(this).parents("tr").after('<tr class="tools"><td>3<button class="bb">bb</button></td></tr>')
$(this).attr("value","0")
}else{
$(".tools").remove()
$(this).attr("value","1")
}
})
})
</script>
</head>
<body>
<table>
<tr><td>1</td></tr>
<tr><td>2<button class="aa" value="1">aa</button></td></tr>
<tr><td>4</td></tr>
</table>
</body>
</html>
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)