【发布时间】:2012-05-31 20:49:37
【问题描述】:
我的一个页面有这样的结构:
head
script
/script
/head
body
table1
table2
/body
这里是javascript:
<script type="text/javascript">
$( function() {
$('tr').click( function() {
$(this).parents('table').find('tr').each( function( index, element ) {
$(element).removeClass('selected');
} );
$(this).addClass('selected');
$(this).removeClass('normal');
} );
} );
$( function() {
$('tr').hover( function() {
$(this).addClass('highlight');
$(this).removeClass('normal');
} );
} );
$( function() {
if($('tr').hasClass('selected')) {
}
else {
$('tr').mouseout( function() {
$(this).removeClass('highlight');
} );
}
} );
</script>
table1 是通过加载页面生成的,而 table2 是通过单击 table1 的任意行使用 Ajax 生成的。
单击或悬停时,脚本会向 tr(表格行)添加一些类,以便我可以设置它们的样式(更改背景颜色)
脚本适用于 table1 行并添加类,但不适用于 table2 行!
任何帮助将不胜感激。
【问题讨论】:
-
发布 JavaScript 代码
-
您需要添加更多代码。发布您所指的脚本。
-
请包含实际的表格html和相关的css
标签: javascript jquery ajax hover tablerow