简体   繁体   English

如何隐藏多个表单并显示带有事件单击jQuery的表单之一

[英]how to hide multiple form and show one of form with event click 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隐藏所有内容,当我单击btn-primary之一时,将根据每一行显示和隐藏。

jquery jQuery的

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

html 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? 为什么不全部隐藏? 在此处输入图片说明 when I click one of the button masuk (class btn-primary) then show 当我单击按钮masuk(btn-primary类)之一时,然后显示 在此处输入图片说明 I want when clik click one of the button masuk (class btn-primary)then show and other still hidden 我想要在单击按钮masuk(btn-primary类)按钮之一后显示,而其他按钮仍然隐藏

Change your ids to class . 将您的ids更改为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();
});

Your html id-s should be unique for the page. 您的html id应该是该页面的唯一。 Try to add unique id-s to the forms because now you are assingning them the same value "formmasuk" 尝试向表单添加唯一的id,因为现在您要赋予它们相同的值“ formmasuk”

you need to first add Jquery library to your dom add this link in your index.html 您需要先将Jquery库添加到您的dom中,然后在index.html中添加此链接

         ["http://code.jquery.com/jquery-2.2.4.min.js"
          integrity="sha256-BbhdlvQf/xTY9gja0Dq3HiwQF8LaCRTXxZKRutelT44="
          crossorigin="anonymous"]

and remove the second line of the code datatable from your script then code is working fine and also please end your script tag properly. 并从脚本中删除代码数据表的第二行,那么代码工作正常,还请正确结束脚本标记。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM