我試圖突出顯示錶中有人點擊它時出現的一行。這裏是我的表:使用jquery addclass將css添加到表
<table class="pretty">
<tr>
<td onclick="DoNav('<?php echo $url; ?>');">Name</td>
<td onclick="DoNav('<?php echo $url; ?>');">Time</td>
<td onclick="DoNav('<?php echo $url; ?>');">Size</td>
<td onclick="DoNav('<?php echo $url; ?>');">Length<td>
<td><input type="checkbox" value="<?php echo $this->result_videos[$i]["video_name"]; ?>" title="Mark this video for deletion" /></td>
</tr>
...
我試圖在此基礎上post一些事情:
jQuery("table tr").click(function(){
var row = jQuery(this);
var hasClass = row.hasClass("highlight");
jQuery("table tr").removeClass("highlight");
if(!hasClass){
row.addClass("highlight");
alert("Do I get here?");
}
});
我的CSS。 編輯:新增完整的CSS這可能是問題:
table.pretty {
width: 100%;
border-collapse: collapse;
font-family: "Lucida Sans Unicode","Lucida Grande",Sans-Serif;
clear: both;
}
/* Header cells */
table.pretty thead th {
background: none repeat scroll 0 0 #808184;
border-bottom: 1px solid #2B3D61;
border-top: 4px solid #2B3D61;
color: #ffffff;
font-size: 14px;
font-weight: normal;
padding: 8px;
text-shadow: 0 1px 0 rgba(0, 0, 0, 0.4);
text-align: center;
}
/* Body cells */
table.pretty tbody th {
background: none repeat scroll 0 0 #808184;
border-bottom: 1px solid #2B3D61;
border-top: 4px solid #2B3D61;
color: #ffffff;
font-size: 14px;
font-weight: normal;
padding: 8px;
text-shadow: 0 1px 0 rgba(0, 0, 0, 0.4);
}
table.pretty tbody td {
background: none repeat scroll 0 0 #eeeeee;
border-bottom: 1px solid #2B3D61;
border-top: 1px solid transparent;
color: #333333;
padding: 8px;
text-align: center;
}
table.pretty tbody tr {
cursor: pointer;
}
/* Footer cells */
table.pretty tfoot th {
background: none repeat scroll 0 0 #808184;
border-bottom: 1px solid #2B3D61;
border-top: 4px solid #2B3D61;
color: #ffffff;
font-size: 14px;
font-weight: normal;
padding: 8px;
text-shadow: 0 1px 0 rgba(0, 0, 0, 0.4);
text-align: left;
}
table.pretty tfoot td {
background: none repeat scroll 0 0 #808184;
border-bottom: 1px solid #2B3D61;
border-top: 4px solid #2B3D61;
color: #ffffff;
font-size: 14px;
font-weight: normal;
padding: 8px;
text-shadow: 0 1px 0 rgba(0, 0, 0, 0.4);
text-align: center;
}
.highlight{
background-color: #a8cb17;
}
出於某種原因,該行顏色沒有變化。我試着在DoNav函數中放置jquery代碼(減去點擊),它在你點擊該行時只是開始一個視頻。
我在做什麼錯。提前致謝。
你能提供一個小提琴嗎?我可以看到這段代碼沒有錯。 –
也許表是動態構建的?如果是這樣,你需要委託 –
也許表格單元有自己的背景,隱藏行背景? –