English 中文(简体)
AJAX: 一行的 CSS 样式应用程序
原标题:AJAX: CSS style application to a row

我需要以下代码的帮助。 有两个样式 : < code> activatedRow 和 < code> disactivatedRow 。 当用户点击按钮( 位于表格的TD) 时, 要么将 < code> activatedRow 或 < code> disactivatedRow 应用到一行。 样式的选择以当前样式为基础。 例如, 如果启用一个行, 则按钮会关闭它, 反之亦然 。

因此,我对 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;
      });
最佳回答

如果 obj 是用于应用样式的TD, 正如您的代码所示, 您可以使用 < a href=> http://api.jquery.com/toggleClass/" rel="nofolp"\\\code>toggleClass

从一组匹配元素中的每个元素中添加或删除一个或一个以上的类别,取决于类别的存在或开关参数的价值。

$(obj).closest( tr ).toggleClass( disactivatedRow );
$(obj).closest( tr ).toggleClass( activatedRow );

<强 > EDIT

根据您添加的新信息, obj 是一个行子。 closest 方法应该为您提供 Appropiate tr , 然后我们就可以应用 toggleClass

问题回答

暂无回答




相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签