简体   繁体   English

当我单击一个 div 然后它隐藏其他 div 时我想做

[英]I want to do when I click on one div then it hides other div

This code is working till div8 but doesn't work after div8 why is this happening please help me out and one more thing plz also explain it if you correct this code and this problem coming because this method doesn't work for more div sorry I know this is silly question.此代码在 div8 之前有效,但在 div8 之后无效,为什么会发生这种情况,请帮帮我,如果您更正此代码并且出现此问题,请再解释一件事,因为此方法不适用于更多 div 对不起,我知道这是个愚蠢的问题。 Thanks in advance提前致谢

  <div style="flex: 1">
        <label class="ac_trigger" for="ac1">Sweets</label>
        <input type="checkbox" class="ac_hide"  onclick="showHide(this,'div1')" id="ac1" name="x1">
      </div>
      <div class="ac_container" id="div1">
        {% for a,b in sweets.items %}
        <table class="foods">
          <tr>
            <th id="{{b}}">{{b}}</th><td><input type="number" name="{{a}}" value="0" id="{{a}}"></td>
          </tr>
        </table>
        {% endfor %}      
      </div>

..................so on to below one.............

      <div style="flex: 1">
        <label class="ac_trigger" for="ac35">Vegitables</label>
        <input type="checkbox" class="ac_hide"  onclick="showHide(this,'div35')" id="ac35" name="x1">
      </div>
      <div class="ac_container" id="div35">
        {% for a,b in veg.items %}
        <table class="foods">
          <tr>
            <th id="{{b}}">{{b}}</th><td><input type="number" name="{{a}}" value="0" id="{{a}}"></td>
          </tr>
        </table>
        {% endfor %}      
      </div>
     </div> 


    </div>
    <div style="text-align: center;">
      <button>Submit</button>
    </div>
  </form>
  <script type="text/javascript">
  function showHide(tagData, divId){
    let allInputs = ['ac1','ac2','ac3','ac4','ac5','ac6','ac7','ac8','ac9','ac10','ac11','ac12','ac13','ac14','ac15','ac16','ac17','ac18','ac19','ac20','ac21','ac22','ac23','ac24','ac25','ac26','ac27','ac28','ac29','ac30','ac31','ac32','ac33','ac34','ac35'];
   let divToChange = document.getElementById(divId);
   divToChange.style.display = tagData.checked ? "block" : "none";
   if(tagData.checked){
   for(let i = 0 ; i = allInputs.length ; i++){
     if(tagData.id !== allInputs[i]) {
       let divToHideId = 'div'+allInputs[i].substr(allInputs[i].length - 1)
       document.getElementById(divToHideId).style.display = 'none'
       document.getElementById(allInputs[i]).checked = false
     }
   }
   }
   
  };
  </script>

It seems like you are missing something there.好像你在那里遗漏了一些东西。

<script type="text/javascript">
  function showHide(tagData, divId){
    let allInputs = ['ac1','ac2','ac3','ac4','ac5','ac6','ac7','ac8','ac9','ac10','ac11','ac12','ac13','ac14','ac15','ac16','ac17','ac18','ac19','ac20','ac21','ac22','ac23','ac24','ac25','ac26','ac27','ac28','ac29','ac30','ac31','ac32','ac33','ac34','ac35'];
    let divToChange = document.getElementById(divId);
    divToChange.style.display = tagData.checked ? "block" : "none";
    if(tagData.checked){

      //TRY TO USE for(let i = 0;i<=allInputs.length;i++)

      for(let i = 0 ; i = allInputs.length ; i++){
        if(tagData.id !== allInputs[i]) {
          let divToHideId = 'div'+allInputs[i].substr(allInputs[i].length - 1)
          document.getElementById(divToHideId).style.display = 'none'
          document.getElementById(allInputs[i]).checked = false
        }
      }
    }
        
  };

</script>

function which we required for this question i am very happy right now.....best regards for others function 我们需要这个问题我现在很高兴.....向他人致以最诚挚的问候

function showHide(evt, divId) {
  var i, tabcontent, tablinks;
  tabcontent = document.getElementsByClassName("ac_container");
  for (i = 0; i < tabcontent.length; i++) {
    tabcontent[i].style.display = "none";
  }
  tablinks = document.getElementsByClassName("ac_hide");
  for (i = 0; i < tablinks.length; i++) {
    tablinks[i].className = tablinks[i].className.replace(" active", "");
  }
  document.getElementById(divId).style.display = "block";
  evt.currentTarget.className += " active";
}

家长<div>当我点击它时隐藏</div><div id="text_translate"><p>我有一个输入字段,当我单击它时,将显示一个&lt;div&gt; 。 但是由于某种原因,当我单击&lt;div&gt;时,它会隐藏起来,我似乎找不到问题所在。</p><p> <a href="http://jsfiddle.net/Kq9pX/" rel="nofollow noreferrer">JSfiddle</a> </p><p></p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false"><div class="snippet-code"><pre class="snippet-code-js lang-js prettyprint-override"> $('#searchid').blur(function() { if ($(this).val().= "") { $("#drope_box");show(). } else { $("#drope_box");hide(); } }). $('#searchid').focus(function() { $("#drope_box");show(); });</pre><pre class="snippet-code-html lang-html prettyprint-override"> &lt;script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.9.1/jquery.min.js"&gt;&lt;/script&gt; &lt;div class="banner_search_inner_box_search"&gt; &lt;input type="text" name="search" class="search" id="searchid" onkeyup="getshows();" value="" placeholder="Enter a City,Locality" autocomplete="off"&gt; &lt;div id="result"&gt;&lt;/div&gt; &lt;/div&gt; &lt;div id="drope_box" style="display:none;"&gt; &lt;div class="banner_search_type"&gt; &lt;select id="property_type" name="property_type"&gt; &lt;option value="All"&gt;All&lt;/option&gt; &lt;option value="Apartment"&gt;Apartment&lt;/option&gt; &lt;option value="Plot"&gt;Plot&lt;/option&gt; &lt;/select&gt; &lt;/div&gt; &lt;div class="banner_search_price_min"&gt; &lt;select name="price_min" class="search_list" id="price_min"&gt; &lt;option value=""&gt;Price Min&lt;/option&gt; &lt;option value="100000"&gt;1 lac&lt;/option&gt; &lt;option value="1000000"&gt;10 lacs&lt;/option&gt; &lt;/select&gt; &lt;/div&gt; &lt;div class="banner_search_price_max"&gt; &lt;select name="price_max" id="price_max"&gt; &lt;option value=""&gt;Price Max&lt;/option&gt; &lt;option value="100000"&gt;1 lac&lt;/option&gt; &lt;option value="1000000"&gt;10 lacs&lt;/option&gt; &lt;/select&gt; &lt;/div&gt; &lt;/div&gt;</pre></div></div><p></p></div> - Parent <div> hides when I click it

暂无
暂无

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

相关问题 我要在单击一个div时隐藏所有其他div - I want to hide all other div's when i click on one div 家长<div>当我点击它时隐藏</div><div id="text_translate"><p>我有一个输入字段,当我单击它时,将显示一个&lt;div&gt; 。 但是由于某种原因,当我单击&lt;div&gt;时,它会隐藏起来,我似乎找不到问题所在。</p><p> <a href="http://jsfiddle.net/Kq9pX/" rel="nofollow noreferrer">JSfiddle</a> </p><p></p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false"><div class="snippet-code"><pre class="snippet-code-js lang-js prettyprint-override"> $('#searchid').blur(function() { if ($(this).val().= "") { $("#drope_box");show(). } else { $("#drope_box");hide(); } }). $('#searchid').focus(function() { $("#drope_box");show(); });</pre><pre class="snippet-code-html lang-html prettyprint-override"> &lt;script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.9.1/jquery.min.js"&gt;&lt;/script&gt; &lt;div class="banner_search_inner_box_search"&gt; &lt;input type="text" name="search" class="search" id="searchid" onkeyup="getshows();" value="" placeholder="Enter a City,Locality" autocomplete="off"&gt; &lt;div id="result"&gt;&lt;/div&gt; &lt;/div&gt; &lt;div id="drope_box" style="display:none;"&gt; &lt;div class="banner_search_type"&gt; &lt;select id="property_type" name="property_type"&gt; &lt;option value="All"&gt;All&lt;/option&gt; &lt;option value="Apartment"&gt;Apartment&lt;/option&gt; &lt;option value="Plot"&gt;Plot&lt;/option&gt; &lt;/select&gt; &lt;/div&gt; &lt;div class="banner_search_price_min"&gt; &lt;select name="price_min" class="search_list" id="price_min"&gt; &lt;option value=""&gt;Price Min&lt;/option&gt; &lt;option value="100000"&gt;1 lac&lt;/option&gt; &lt;option value="1000000"&gt;10 lacs&lt;/option&gt; &lt;/select&gt; &lt;/div&gt; &lt;div class="banner_search_price_max"&gt; &lt;select name="price_max" id="price_max"&gt; &lt;option value=""&gt;Price Max&lt;/option&gt; &lt;option value="100000"&gt;1 lac&lt;/option&gt; &lt;option value="1000000"&gt;10 lacs&lt;/option&gt; &lt;/select&gt; &lt;/div&gt; &lt;/div&gt;</pre></div></div><p></p></div> - Parent <div> hides when I click it 我想当我点击模态上的单选按钮(objectart)时,它应该在另一个 div(objecttype)中更改模态上的其他 div 数据(获取数据库) - i want when i click on radio button (objectart) on modal then it should change other div data (fetch database) on modal in another div(objecttype) 当我单击其他div时使div出现 - Make div appear when i click in other div 我想用div来代替另一个div - I want to show the div in place of the other div javascript中的动画功能,当我单击它时需要对某物进行动画处理,以便一个div进入1种方式,另一个div进入另一种方式 - Animate function in javascript, I need to animate something when I click on it so that one div goes 1 way and the other div goes the other way 当我单击按钮时,我想随机旋转“ div” - I want to rotate a “div” randomly, when i click a button 一格中有图标和标签,单击标签后我想更改图标 - There are icon and label in one div, I want to change icon on click of label 当你点击一个按钮时,我想让一个 div 出现 - I want to make a div appear when you click a button 我要始终在单击“提交”按钮时删除div容器吗? - I want to remove the div container always when click submit button?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM