weixin_33713707 2016-10-24 12:43 采纳率: 0%
浏览 67

在ajax中切换开关

I have written below code in PHP + Ajax

<table>
  <tr><td data-id="1" onclick="showData(event);">ABC</td>
  <tr style='display:none' data-fold='1'><td>ABC - 01</td>
  <tr><td data-id="2" onclick="showData(event);">PQR</td>
  <tr style='display:none' data-fold='2'><td>PQR- 01</td>
</table>

I need to show data-fold "tr" when someone click on data-id with respective id, that is when I click on data-id 1, then data-fold 1 should be visible.

Also, the content in data-fold is coming from AJAX..

Below is my AJAX code:

function showData(event){

var rowId = $(event.currentTarget).attr('data-id'); 
$.ajax({
        type: "POST",
        url: "ajax.php", // 
        data: 'type=viewOrder&rowId='+rowId,            
        success: function(msg){ 

            $("tr").each(function(){                    
                childId = $(this).attr('data-fold');   
                if(childId == rowId) {
                    $(this).toggle("slow");
                    $(this).html(msg);
                }
            });

        },
        error: function(){
            alert("failure");
        }
    });

   }

My code is working fine, but I need to close all other tr expect the one I clicked.

  • 写回答

0条回答

      报告相同问题?

      相关推荐 更多相似问题

      悬赏问题

      • ¥15 使用自定义的类型代替内置类型可行吗
      • ¥15 关于STM32的SPI和ENDAT接口编码器通信的问题
      • ¥15 关于#pdfbox#生成的PDF文件正常,转图片中文乱码的问题,如何解决?
      • ¥15 ADS中有关DAC控件的使用问题
      • ¥15 win11如何运行geoserver
      • ¥15 审稿意见请教-用ERNIE进行小样本分类的对比实验问题
      • ¥15 gem5搭建arm v8
      • ¥15 安卓时间管理APP,怎么做
      • ¥15 这段有什么bug 为什么总报错
      • ¥15 Intel Realsense深度相机(D415/D435)拍摄梯子获取梯子点云