我有一个与表格高亮和取消高亮相关的问题! 我有一个表格,当我点击一个 td 时,它会高亮显示,但是当我点击另一个 td 时,它也会高亮显示,但我的第一次点击(被高亮显示)并没有消失。
这是我的 php 代码:
<table class="cg-nav-wrapper cg-nav-wrapper-row-2" id="tableID" data-role="cg-nav-wrapper">
<tr>
<?php
include 'includes/connection/dbh.inc.php';
$categories =array("Agriculture & Food", "Apparel, Textiles & Accessories", "Maintenance & Repair", "Auto & Transportation", "Business & Commercial", "Computer Electronics", "Electronics & Electrical Equipment", "Health & Beauty", "Home, Lights & Construction", "House Cleaning", "House Improvement", "Machinery, Industrial Parts & Tools", "Packaging, Advertising & Office");
$len = count($categories);
for($x = 0; $x < $len; $x++) {
$current = $categories[$x];
$sql = "SELECT count(company_business_category) AS total FROM businesses WHERE company_business_category ='$current' ";
$result = mysqli_query($conn, $sql);
$count=mysqli_fetch_assoc($result);
$num = $count['total'];
if($current=='Agriculture & Food'){
if($num>0){
?>
<td class="anchor-wrap anchor1-wrap" data-role="anchor1">
<a class="anchor1 anchor-agricuture showSingle click-here agricutureTD" inputtype="checkbox" target="1" data-role="cont" >
<i class="cg-icon"></i>
<span class="desc">
Agriculture & Food
</span>
</a>
</td>
<?php
}else{
?>
<td class="anchor-wrap anchor1-wrap" data-role="anchor1">
<a class="anchor1 anchor-agricuture click-here agricutureTD"
data-role="cont" >
<i class="cg-icon"></i>
<span class="desc">
Agriculture & Food
</span>
</a>
</td>
<?php
}
}
else if($current=='Apparel, Textiles & Accessories'){
if($num>0){
?>
<td class="anchor-wrap anchor2-wrap showSingle apparelTD " target="2" data-role="anchor2">
<a class="anchor2 anchor-apparel click-here apparelTD" data-role="cont" >
<i class="cg-icon"></i>
<span class="desc">
Apparel,Textiles & Accessories
</span>
</a>
</td>
<?php
}else{
?>
<td class="anchor-wrap anchor2-wrap cl apparelTD" target="2" data-role="anchor2">
<a class="anchor2 anchor-apparel click-here apparelTD" data-role="cont">
<i class="cg-icon"></i>
<span class="desc">
Apparel,Textiles & Accessories
</span>
</a>
</td>
<?php
}
}
}
?>
</table> ....
这是我的js代码:
$(document).ready(function(){
var target = $('.cg-main').html();
var nothing = '<div class="item util-clearfix targetDiv" data-spm="1" id="div1">' +
'<h3 class="big-title anchor1'+
'404 Nothing Found' +
'</h3>'+
'<div class="sub-item-wrapper util-clearfix">'+
'<div class="sub-item">'+
''+
'</div>'+
'</div>'+
'</div>';
$('.click-here').on('click',function(){
var $td = $(this).parent();
$('.click-here').not(this).removeClass("selected");
$td.toggleClass("selected");
});
});
如何取消之前的点击高亮?有人能帮我吗?我被卡住了。