<!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>
str += "<tr ondblclick='changebgColor(this)'>" //行循环增加双击事件//js方法
<script type="text/javascript" language="javascript">
function changebgColor(obj){
if(obj.bgColor=="#FF0000") obj.bgColor =""
else obj.bgColor="#FF0000"//双击变色,再双击变回
//也可以通过obj.style.backgroundColor="#FF0000"这样来设置,一个是通过属性来设置,一个是通过样式来设置
}
</script>
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)