
假设:
html代码:
<table id="test">
.....
</table>
在js脚本中增加:
$("#test tr").onClick(function(){
JsTest()
})
备注:
jQuery下载地址:
http://jQuery.com
先在样式表中写好点击的效果,然后在通过JS来添加删除这个样式就可以了,具体看下面这个例子<!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>
分两种情况,第一td是现成的,不需要jQuery来加,这样 你直接调用each方法就行,里面有个变量i 每次都加1第二种情况td未知,这样的话,就直接for循环好了,每次循环都加一遍td和里面的id 循环外面定义一个html 这样到之后html里面就是所有的td 把他直接append到指定的tr下面就可以了
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)