【问题标题】:Checkbox/Button submit hide class/ID复选框/按钮提交隐藏类/ID
【发布时间】:2014-04-10 06:06:57
【问题描述】:

我想做的事情很简单,但我不知道该怎么做。

我在 HTML 文件中为容器提供了一个 Div ID/Class。

现在我想在 php 文件中添加一个复选框或按钮,它可以隐藏和显示 HTML 文件中的 div 元素。

我想做什么:

  1. 通常对所有人可见。
  2. 我检查了隐藏打开并单击了提交。
  3. 移除容器或将可见性更改为无。

【问题讨论】:

    标签: php html css checkbox


    【解决方案1】:

    如果我理解你的话,试试这个: http://www.w3schools.com/jquery/tryit.asp?filename=tryjquery_hide_show

    只需将按钮更改为复选框,并进行一些检查,如果选中了复选框,则隐藏其他显示

    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>

    <script>
    $(document).ready(function(){
    $('#showHide').change(function(){
        var c = this.checked ? $("p").show() : $("p").hide();  
    }); 
    });
    </script>
    
    
    <p>If you click on the "Hide" button, I will disappear.</p>
    <input type="checkbox" id="showHide" name="showHide" value="Show">Check it
    

    【讨论】:

      【解决方案2】:

      使用这个 Javascript(你不必使用 Jquery):

      <script type="text/javascript">
      function showHide(thediv){
         id = document.getElementById(thediv).style;
         id.display = (id.display != 'inline')? 'inline' : 'none';
      }
      </script>
      

      然后定义你要隐藏的div:

      <div style="display:none" id="my_div">
           Hello World or any other HTML
      </div>
      

      现在 - 在代码中的某个位置设置单选按钮,并在点击时触发显示脚本:

      <input type="radio" onclick="showHide('my_div')" />
      

      如果您希望 div 显示为默认值,请更改为

      <div style="display:inline" id="my_div">
      

      或者只是完全删除样式。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2018-04-16
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-03-13
        • 1970-01-01
        相关资源
        最近更新 更多