简体   繁体   English

单击我的图标时如何显示和隐藏我的内容

[英]How to show and hide my contents when I click my icon

I just created a card-form(bootstrap) and in the form, there are a plus icon and hidden contents( id=mycontent_1 with display: none ).我刚刚创建了一个卡片表单(引导程序),在表单中,有一个加号图标和隐藏的内容( id=mycontent_1 with display: none )。 what I'm trying to do is listed as follows.我正在尝试做的是如下所列。 I tried to do the first one on my java-script but it's not working.我试图在我的 java 脚本上做第一个,但它不起作用。

  1. when I click plus icon, my function(toggler) should be executed and the icon would be hidden and my contents(text boxes and delete button) have to be visible.当我点击加号图标时,我的功能(切换器)应该被执行并且图标将被隐藏并且我的内容(文本框和删除按钮)必须是可见的。

  2. similarly in opposite direction, when I click the delete button, my contents(text boxes and a delete button) have to be invisible and the plus icon should be visible.同样在相反的方向,当我单击删除按钮时,我的内容(文本框和删除按钮)必须不可见,加号图标应该可见。

need your kind helps for my two functions.我的两个功能需要您的帮助。 here are my codes for jsfiddle.这是我的 jsfiddle 代码。

https://jsfiddle.net/Sanchez/aq9Laaew/219304/ https://jsfiddle.net/Sanchez/aq9Laaew/219304/

       <div class="col-sm-6">
            <div class="card">
              <div class="card-header" id="cardHeader1" style="visibility: hidden;"> no name </div>
          <div class="card-body">
            <a href="#" class="btn btn-info btn-lg" onclick="toggler('myContent_1');">
              <span class="glyphicon glyphicon-plus" id=icon1  onclick="toggler('myContent_1');"></span> Plus 
            </a>
                <div id="myContent_1" class="card-title" style="display: none;" >
              <form action="" method="post">
                <div class="form-group">
                  <div class="input-group">
                    <div class="input-group-prepend">
                      <span class="input-group-text">Number</span>
                    </div>
                    <input type="text" id="notiSeq_1" name="notiSeq" class="form-control" value="">
                    <div class="input-group-append">
                    <span class="input-group-text">
                      <i class="fa fa-sort-numeric-asc"></i>
                    </span>
                    </div>
                  </div>
                </div>
                <div class="form-group">
                  <div class="input-group">
                    <div class="input-group-prepend">
                      <span class="input-group-text">Title</span>
                    </div>
                    <input type="text" id="title_1" name="title" class="form-control" value="">
                    <div class="input-group-append">
                    <span class="input-group-text">
                      <i class="fa fa-tumblr"></i>
                    </span>
                    </div>
                  </div>
                </div>

                <div class="form-group form-actions">
                   <button type="button" id="delBtn_1" class="btn btn-danger">Delete</button>
                </div>
                </form>
                </div>
                </div>
                </div>
                </div>



function toggler(divId){  

   var tempId = divId.slice(-1);
   var x = document.getElementById("icon" + tempId);
   var y = document.getElementById("cardHeader" + tempId);
   x.style.display = "none";
   y.style.visibility = "visible";
   $("#delBtn_" + tempId).show();
   $("#" + divId).toggle();

}

To begin with you should place you js code on the head before the body.首先,您应该将 js 代码放在身体之前的头部。 Afterwards, replace the a tag with button Finally call toggler function on delete button's onclick之后,用button替换a标签最后在删除按钮的 onclick 上调用toggler功能

<script>
   function hidePlusBtn() {
       $("#plusBtn").hide();
   }

   function toggler(divId) {  
       var tempId = divId.slice(-1);
       var x = document.getElementById("icon" + tempId);
       var y = document.getElementById("cardHeader" + tempId);
       x.style.display = "none";
       y.style.visibility = "visible";
       $("#delBtn_" + tempId).show();
       $("#" + divId).toggle();
   }
</script>  

<div class="col-sm-6">
      ...
     <button 
            id="plusBtn" 
            class="btn btn-info btn-lg" 
            onclick="toggler('myContent_1');">
              <span 
                  class="glyphicon glyphicon-plus" 
                  id=icon1  
                  onclick="toggler('myContent_1');">
              </span> Plus 
    </button>
     ...
     <button 
          type="button" 
          id="delBtn_1" 
          class="btn btn-danger" 
          onclick="toggler('myContent_1'); hidePlusBtn()">Delete
     </button>
  ...
</div>

Updated Demo: https://jsfiddle.net/1s390orm/更新演示: https : //jsfiddle.net/1s390orm/

暂无
暂无

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

相关问题 使用jquery点击眼睛图标时如何显示和隐藏密码 - How to show and hide password when click on eye icon using jquery 单击“其他”时如何隐藏我的滑动侧导航? - How to hide my sliding side nav when i click elsewere? 单击侧边栏时如何隐藏我的表格? 并且当我单击按钮显示另一个表时,当前打开的表会关闭吗? - How can I hide my table when I click in the sidebar? and Also when I click the button to show another table the current open table will close? flexslider如何在单击背景时显示我的照片灯箱 - flexslider How to show my photo lightbox when i click background 为什么我不能单击功能来显示和隐藏? - Why I can not click on my function to show and hide? 如何对我的单击功能进行条件显示和隐藏模态 - How to make a conditional show and hide modal to my on click function 为什么单击菜单图标时我的正常导航栏消失了 - Why is my normal navbar disappearing when I click on the menu icon 我希望我的按钮隐藏并只显示我点击的卡片的内容而不影响其他人 - I want my button to hide and show only the contents of the card I clicked on not without affecting the others 当我在开启器中放置表格或 div 元素时,如何单击我的开启器并显示我的内容 - How to click on my opener and show my content, when i placed tables or div elements inside the opener 当我单击它们时,如何让我的按钮正确隐藏/显示? - How can I get my buttons to hide/display properly when I click them?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM