我需要以下代码的帮助。 有两个样式 : < code> activatedRow code > 和 < code> disactivatedRow code > 。 当用户点击按钮( 位于表格的TD) 时, 要么将 < code> activatedRow code > 或 < code> disactivatedRow code > 应用到一行。 样式的选择以当前样式为基础。 例如, 如果启用一个行, 则按钮会关闭它, 反之亦然 。
因此,我对 AJAX 成功
有问题。 如何写入 IF 语句以检查行的当前样式?
P.S.还想知道如何将TD IMG(按钮)改为已停用和激活的行。
<强 > CSS 强 >
.activatedRow td {
background-color:#FFFFFF !important;
color: #000000 !important;
}
.disactivatedRow td {
background-color:#DFE1ED !important;
color: #9896A8 !important;
}
<% 1\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
<script type="text/javascript">
function disactivateRow(flightNum,obj){
$.ajax({
type: "POST",
url: "callpage.php?page=tables/disactivate.php",
data: "flightNum=" + flightNum,
success: function(){
if ($(obj).hasClass("activatedRow")) {
$(obj).removeClass("activatedRow").addClass("disactivatedRow");
} else
$(obj).removeClass("disactivatedRow").addClass("activatedRow");
}
});
}
</script>
表格中 < 坚固 > 按钮 坚固>
<table id="newspaper-b" border="0" cellspacing="2" cellpadding="2" width = "100%">
<thead>
<tr>
<th scope="col">Flt Num</th>
<th scope="col"></th>
</tr>
</thead>
<tbody>
<?php foreach ($result1 as $row):
$flightNum=$row[ flightNum ];
?>
<tr id="<?php echo $flightNum; ?>" class="edit_tr">
<td><?php echo $flightNum;?></td>
<td id="<?php echo $flightNum; ?>">
<div onclick= disactivateRow("<?php echo $flightNum; ?>", this) >
<img src= images/disactivate.png alt= Disactivate />
</div>
</td>
</tr>
<?php endforeach;?>
</tbody>
</table>
<强度>jQuery 数据表激活 强度>
$(document).ready(function(){
$( #newspaper-b ).dataTable({
"sPaginationType":"full_numbers",
"bJQueryUI":true,
fnRowCallback : function(nRow, aData, iDisplayIndex, iDisplayIndexFull) {
if (aData[0] == "0") {
nRow.className = "disactivatedRow";
} else
nRow.className = "activatedRow";
return nRow;
}
});
<强>ANSWER: 强>
它现在起作用了:
$(".disact_but" ).click(function() {
var ID=$(this).attr( id );
$.ajax({
type: "POST",
url: "callpage.php?page=tables/disactivate.php",
data: "flightNum=" + ID,
success: function(){
$("#"+ID).toggleClass("disactivatedRow", 100);
}
});
return false;
});