ITeye博客

JQuery表的操作

Ueaner · 2010-05-27 17:51 · jQuery · Web前端 · HTML · CSS · jQuery · JavaScript · Markdown

二、操作 1.鼠标移动行变色 [code="javascript"]$("#table1 tr").hover(function(){ $(this).children("td").addClass("hover") },function(){ $(this).children("td").removeClass("hover") }) $("#table2 tr:gt(0)").hover(function() { $(this).children("td").addClass("hover"); }, function() { $(this).children("td").removeClass("hover"); }); [/code] 2.奇偶行不同颜色 [code="javascript"]$("#table3 tbody tr:odd").css("background-color", "#bbf"); $("#table3 tbody tr:even").css("background-color","#ffc"); $("#table3 tbody tr:odd").addClass("odd") $("#table3 tbody tr:even").addClass("even") [/code] 3.隐藏一行 [code="javascript"]$("#table3 tbody tr:eq(3)").hide(); [/code] 4.隐藏一列 [code="javascript"]$("#table5 tr td::nth-child(3)").hide(); $("#table5 tr").each(function(){$("td:eq(3)",this).hide()});[/code] 5.删除一行 [code="javascript"] // 删除除第一行外的所有行 $("#table6 tr:not(:first)").remove(); [/code] 6.删除一列 [code="javascript"]// 删除除第一列外的所有列 $("#table6 tr td:not(:nth-child(1))").remove(); [/code] 7.得到(设置)某个单元格的值 [code="javascript"]//设置table7,第2个tr的第一个td的值。 $("#table7 tr:eq(1) td:nth-child(1)").html("value"); //获取table7,第2个tr的第一个td的值。 $("#table7 tr:eq(1) td:nth-child(1)").html(); [/code] 8.插入一行: [code="javascript"]//在第二个tr后插入一行 $("插入3插入插入插入").insertAfter($("#table7 tr:eq(1)"));[/code] 来自:Forgot.

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。