您的位置:首页 > Web前端 > JQuery

Jquery 动态生成表格 并为行绑定单击变色动作

2013-05-29 23:39 429 查看
<html>
<head>
<script type="text/javascript" src="/jquery/jquery.js"></script>
<script type="text/javascript">
$(function(){


/////////////////以下动态生成10行2列的表格

for(i=1;i<=10;i++)
{
$("#mytable").append("<tr><td> </td><td> </td></tr>");
}

/////////////表格生成结束

/////////////为生成的行添加单击变色动作

$"#mytable tr").click(function(){
if($(this).hasClass("redcss"))
{

$(this).siblings("tr").removeClass("redcss");
}
else
{
$(this).addClass("redcss");
$(this).siblings("tr").removeClass("redcss");
}

})

})

</script>
<style>
.redcss{
background-color:#900;
}

</style>
</head>
<body>
<table width="200" border="1" id="mytable"></table>
</table>
</body>
</html>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: