[removed] How to Hide / Unhide

后端 未结 5 2042
我在风中等你
我在风中等你 2020-12-19 02:25

I\'m trying to avoid using innerHTML because it causes my browser to crash, probably due to the 250 milliseconds refresh rate.

Anyway, I would rather ha

相关标签:
5条回答
  • 2020-12-19 03:01

    You could either set the display property to none or the visibility property to hidden.

    0 讨论(0)
  • 2020-12-19 03:02

    Set the display CSS property of the div to none.

    https://developer.mozilla.org/en-US/docs/CSS/display

    Example of setting it programmatically with Javascript: http://jsbin.com/ezanuv/1/edit

    0 讨论(0)
  • 2020-12-19 03:08

    Then use CSS to hide and unhide the div. You can do something like this:

        changeIt.style.visibility = 'hidden';
    

    to make the div disappear. And

       changeIt.style.visibility = 'visible';
    

    to show it again.

    0 讨论(0)
  • 2020-12-19 03:14

    I prefer using css display property. I have a running code which I wrote recently. Its very simple and scalable as well.

      <HEad>
        <script src="http://code.jquery.com/jquery-1.8.3.min.js"></script>
        <script> 
           $(document).ready(function() {
             $.setDisplay = function (id){
               if($("#" + id ).css('display') == 'none'){
                 $("#" + id ).css('display', 'block');
               }
               else
               if($("#" + id ).css('display') == 'block'){
                 $("#" + id ).css('display', 'none');
               }
             }
    
             $('*[id^="divheader"]').click(function (){
                $.setDisplay($(this).data("id"));
             });
           });
         </script>
      </HEad>        
    
    <div id='divheader-div1' data-id='div1'>
      This is the header Click to show/unshow
    </div>
    <div id='div1' style='display: block'>
      <div>
        <label for="startrow">Retail Price:</label>
        <input type="text" name="price" id="price" value=""><small></small>
      </div>
    </div>
    
    <div id='divheader-div2' data-id='div2'>
     This is the header Click to show/unshow
    </div>
    <div id='div2' style='display: none'>
     <div>
       <label for="startrow">Division:</label>
       <input type="text" name="division" id="division" value=""><small> </small>
     </div>
    </div>
    
    0 讨论(0)
  • 2020-12-19 03:26

    The best way is to set the display none for hidden and block for visible

    //the element is the div you want to hide or display

    element.style.display = (element.style.display == "block") ? "none": "block";

    0 讨论(0)
提交回复
热议问题