我正在使用PHP脚本填充<DIV id='area'>
元素,如果用户希望过滤信息,我希望通过在JavaScript中调用PHP函数来重新填充相同的div元素:
$("#area").load("update-dashboard.php?id=7263");
它用正确的信息填充DIV元素,但由于某种原因,我用来格式化信息的CSS样式(例如class="highlight"
)没有得到应用。因此,如果我查看底层HTML,但浏览器没有根据样式表对其进行格式化,那么我得到的将正确读取。
<style type="text/css">
.Highlight {
background-color: #dcfac9;
cursor: pointer;
}
td.highcell {
padding-top: 8px;
padding-bottom: 8px;
}
</style>
以下是我的表应该包含在DIV部分中的内容:
<table style='border-collapse: collapse;' border=0 width='100%' id='link-table'>
<tr class='highlight'>
<td class='highcell'>
<a href="javascript:ShowWait('754', 'Car Survey', '16', 'NK51+SNR55', '', '');">NK51 SNR55</a>
</td>
<td class='highcell' width=36>
<img src='status_2.png' border=0 width=32 height=32><td class='highcell'>18-Dec-15</td>
<td class='highcell'>NK51 SNR55</td>
<td class='highcell'></td>
<td class='highcell'></td>
</tr>
其他信息:我还使用这个jQuery代码来突出显示表中的行——也许它不适用于页面出现后加载的HTML——如果可以,它可以重新初始化吗?
$(function ()
{
$('#link-table td:first-child').hide();
$('#link-table tr').hover(function ()
{
$(this).toggleClass('highlight');
});
$('#link-table tr').click(function ()
{
location.href = $(this).find('td a').attr('href');
});
});
尝试将css从.Highlight
更改为.highlight
。CSS选择器是不区分大小写的,但HTML类属性不是。