dongmozhui3805 2016-10-15 11:38
浏览 43
已采纳

如何隐藏多个表单并使用事件单击jquery显示表单之一

I'm using jquery to hide all when document ready and when I'm click one of the btn-primary then will be show and hide in accordance with for each of row.

jquery

<script>
$(document).ready(function() {
$('#table').DataTable();
$('#formmasuk').hide();
$('.btn-primary').click(function() {
$('#formmasuk').show();
$('#buttonmasuk').hide();
   });
});
</script?

html

<table id="example1" class="table table-bordered table-striped">
                <thead>
                  <tr style="center">
                    <th>Nik</th>
                    <th>Nama</th>
                    <th>Jabatan</th>
                    <th>Masuk</th>
                    <th>Keluar</th>
                  </tr>
                </thead>
                <tbody>
                  <?php  foreach($query as $row):?>
                <tr>
                    <td><?php echo $row->nik ?></td>
                    <td><?php echo $row->nama ?></td>
                    <td><?php echo $row->jabatan ?></td>
                    <td>
                      <div id='buttonmasuk'>
                          <a class="btn btn-sm btn-primary" href="javascript:void()"
  title="Masuk" onclick="masuk('<?php echo $row->id_kar;?>')">Masuk</a></div>
                      <div id='formmasuk'>
                          <form>
                          <input type="text" name="pass">
                          </form>
                      </div>
                          <td>
                          <a class="btn btn-sm btn-danger"  title="Keluar" ></i>
      Keluar</a></td>
                   </tr>
                    <?php 
                    endforeach ;?>
                </tbody>
              </table>

this image when document ready. why not all hidden? enter image description here when I click one of the button masuk (class btn-primary) then show enter image description here I want when clik click one of the button masuk (class btn-primary)then show and other still hidden

  • 写回答

3条回答 默认 最新

  • dqeq885710 2016-10-15 11:48
    关注

    Change your ids to class.

    It should be like the following

    <div class='buttonmasuk'>
    ...
    <div class='formmasuk'>
    

    and the script be like the following

    $('.formmasuk').hide();
    $('.btn-primary').click(function() {
      $(this).closest('.formmasuk').show();
      $(this).closest('.buttonmasuk').hide();
    });
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度