【问题标题】:Show a pop-up that contains details of every row in html table显示一个弹出窗口,其中包含 html 表中每一行的详细信息
【发布时间】:2015-11-25 05:43:30
【问题描述】:

我有一个这样的 html 表格:

<table id="mytable" class="table table-striped">
<tbody>
    <c:forEach items="${listeCollabDeRrh}" var="collab">
        <tr>
            <td>${collab.matricule }</td>
            <td>${collab.nom }</td>
            <td>${collab.prenom}</td>
            <td hidden="true">${collab.bu.getNomBU()}</td>
            <td hidden="true">${collab.contact}</td>
            <td hidden="true">${collab.dateEmbauche}</td>
            <td>
                <p data-placement="top" data-toggle="tooltip" title="Details">
                    <button class="btn btn-primary btn-xs" data-title="Details" data-toggle="modal" data-target="#Details">	<span class="glyphicon glyphicon-text-color"></span>
                    </button>
                </p>
            </td>
        </tr>
    </c:forEach>
</tbody>
</table>

如果我点击详细信息按钮,我将弹出包含一行所有详细信息的弹出窗口:

<div class="modal-body">
<table id="mytable" class="table table-bordred table-striped">
    <thead>
        <th>Matricule</th>
        <th>Nom</th>
        <th>Pronom</th>
        <th>BU</th>
        <th>Contact</th>
        <th>Date d'ambauche</th>
        <th>RRH</th>
    </thead>
    <tbody>
        <tr>
            <td>matricule of collab</td>
            <td>nom of collab</td>
            <td>prenom of collab</td>
            <td>bu of collab</td>
            <td>contact of collab</td>
            <td>dateEmbauche of collab</td>
        </tr>
    </tbody>
</table>

问题是HTML表格和详情弹窗在同一个jsp页面。我认为我可以将服务器端的控制器与表单一起使用。

当我按下一行的详情按钮时如何显示详情弹窗?

【问题讨论】:

  • 尝试将弹出窗口移动到单独的页面。
  • 我不能,页面是由客户修复的。

标签: javascript jquery html twitter-bootstrap jsp


【解决方案1】:

另一个变体是使用 jQuery。只要用户点击按钮,就会从服务器读取信息。

http://api.jquery.com/jquery.ajax/

为此投入时间,打造更好、更快、数据低调的应用程序。 但如果你不能使用,Farhan 有很好的解决方案。

【讨论】:

    【解决方案2】:

    假设它适用于 UI 上的所有表格:

    <script>
    var cells=document.getElementsbyTagName("td");
    for(i=0;i<cells.length;i++){
    cells[i].onclick=function(){alert(this.innerHTML);};
    }
    </script>
    

    保持 HTML 表格结构正常。那里不需要调用任何函数。

    【讨论】:

      【解决方案3】:

      $(document).ready(function(){
      
          $(".detail_button").on("click",function(){
          	var parentTr = $(this).closest("tr");
              var counter = 1;
              $("td", $(parentTr)).each(function(){
              	if(!($(this).hasClass("detail_td"))){
                      $(".modal-body tr td:nth-child("+counter+")").text($(this).text());
                  	counter++;
                  }
              $(".modal-body").show();
      		$("#bodytable").hide();
      		
              });
          });
      	
      	$("#hide_popup").on("click",function(){
      		$(".modal-body").hide();
      		$("#bodytable").show();
      	});
          
      });
      .modal-body{
          display:none;
          position:absolute;
          top:0;
          left:0px;
      }
      <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>
      <div class="modal-body">
      <input type="button" id="hide_popup" value="Hide Popup"/>
      <div style="clear"></div>
      <table id="mytable" class="table table-bordred table-striped" border="1">
          <thead>
              <th>Matricule</th>
              <th>Nom</th>
              <th>Pronom</th>
              <th>BU</th>
              <th>Contact</th>
              <th>Date d'ambauche</th>
              <th>RRH</th>
          </thead>
          <tbody>
              <tr>
                  <td></td>
                  <td></td>
                  <td></td>
                  <td></td>
                  <td></td>
                  <td></td>
                  <td></td>
                  
              </tr>
          </tbody>
      </table>
      </div>
      
      <table id="bodytable" class="table table-bordred table-striped" border="1">
          <thead>
              <th>Matricule</th>
              <th>Nom</th>
              <th>Pronom</th>
              <th>BU</th>
              <th>Contact</th>
              <th>Date d'ambauche</th>
              <th>RRH</th>
              <th>Detail</th>
          </thead>
          <tbody>
              <tr>
                  <td>1</td>
                  <td>1</td>
                  <td>1</td>
                  <td>1</td>
                  <td>1</td>
                  <td>1</td>
                  <td>1</td>
                  <td class="detail_td">
                      <p data-placement="top" data-toggle="tooltip" title="Details">
                          <button class="detail_button btn btn-primary btn-xs" data-title="Details" data-toggle="modal" data-target="#Details">	<span class="glyphicon glyphicon-text-color">Detail</span>
                          </button>
                      </p>
                  </td>
              </tr>
              <tr>
                  <td>2</td>
                  <td>2</td>
                  <td>2</td>
                  <td>2</td>
                  <td>2</td>
                  <td>2</td>
                  <td>2</td>
                  <td class="detail_td">
                      <p data-placement="top" data-toggle="tooltip" title="Details">
                          <button class="detail_button btn btn-primary btn-xs" data-title="Details" data-toggle="modal" data-target="#Details">	<span class="glyphicon glyphicon-text-color">Detail</span>
                          </button>
                      </p>
                  </td>
              </tr>
          </tbody>
        </table>

      据我了解,您希望在单击详细信息按钮时在弹出窗口中显示相关的行数据。如果不是那么请纠正我 HTML

          <div class="modal-body">
      <input type="button" id="hide_popup" value="Hide Popup"/>
      <div style="clear"></div>
      <table id="mytable" class="table table-bordred table-striped" border="1">
          <thead>
              <th>Matricule</th>
              <th>Nom</th>
              <th>Pronom</th>
              <th>BU</th>
              <th>Contact</th>
              <th>Date d'ambauche</th>
              <th>RRH</th>
          </thead>
          <tbody>
              <tr>
                  <td></td>
                  <td></td>
                  <td></td>
                  <td></td>
                  <td></td>
                  <td></td>
                  <td></td>
      
              </tr>
          </tbody>
      </table>
      </div>
      
      <table id="bodytable" class="table table-bordred table-striped" border="1">
          <thead>
              <th>Matricule</th>
              <th>Nom</th>
              <th>Pronom</th>
              <th>BU</th>
              <th>Contact</th>
              <th>Date d'ambauche</th>
              <th>RRH</th>
              <th>Detail</th>
          </thead>
          <tbody>
              <tr>
                  <td>1</td>
                  <td>1</td>
                  <td>1</td>
                  <td>1</td>
                  <td>1</td>
                  <td>1</td>
                  <td>1</td>
                  <td class="detail_td">
                      <p data-placement="top" data-toggle="tooltip" title="Details">
                          <button class="detail_button btn btn-primary btn-xs" data-title="Details" data-toggle="modal" data-target="#Details">   <span class="glyphicon glyphicon-text-color">Detail</span>
                          </button>
                      </p>
                  </td>
              </tr>
              <tr>
                  <td>2</td>
                  <td>2</td>
                  <td>2</td>
                  <td>2</td>
                  <td>2</td>
                  <td>2</td>
                  <td>2</td>
                  <td class="detail_td">
                      <p data-placement="top" data-toggle="tooltip" title="Details">
                          <button class="detail_button btn btn-primary btn-xs" data-title="Details" data-toggle="modal" data-target="#Details">   <span class="glyphicon glyphicon-text-color">Detail</span>
                          </button>
                      </p>
                  </td>
              </tr>
          </tbody>
        </table>
      

      JQUERY

      $(document).ready(function(){
      
      $(".detail_button").on("click",function(){
          var parentTr = $(this).closest("tr");
          var counter = 1;
          $("td", $(parentTr)).each(function(){
              if(!($(this).hasClass("detail_td"))){
                  $(".modal-body tr td:nth-child("+counter+")").text($(this).text());
                  counter++;
              }
          $(".modal-body").show();
          $("#bodytable").hide();
      
          });
      });
      
      $("#hide_popup").on("click",function(){
          $(".modal-body").hide();
          $("#bodytable").show();
      });
      
      });
      

      CSS

      .modal-body{
          display:none;
          position:absolute;
          top:0;
          left:0px;
      }
      

      演示:https://jsfiddle.net/daf2rLvh/3/

      【讨论】:

      • 很有趣,我会试试,我会给你一个反馈,非常感谢Farhan先生。
      • 如果你不想隐藏基表然后删除 $("#bodytable").hide();和 $("#bodytable").show();来自 Jquery 代码。还为弹出窗口添加样式,如页面叠加
      猜你喜欢
      • 2014-06-19
      • 2021-03-31
      • 1970-01-01
      • 2014-02-04
      • 1970-01-01
      • 2020-09-06
      • 2018-03-11
      • 1970-01-01
      • 2016-01-04
      相关资源
      最近更新 更多