【问题标题】:hide and show div with jquery not working使用jquery隐藏和显示div不起作用
【发布时间】:2016-08-18 10:39:22
【问题描述】:

我正在尝试正常隐藏 div,但在用户单击下拉列表时显示 但不工作的jQuery

<div class="form-group">
    <label>Select Course</label>
    <select name="timepass" class="custom-select">
        <option>Select</option>
        <option id="cour">Php Developer</option>
        <option>Asp.Net</option>
        <option>Python</option>
    </select>
</div>
<div class="mj_tabcontent mj_bottompadder80" id="std-list">
    <table class="table table-striped">
        <tr>
            <td>
                <h4><a href="requirement_detail.html">Mudassir Abbas</a></h4>
            </td>
            </td>
            <td>
                <div class="col-xs-2">
                    <input type="text" placeholder="Grade" class="grade">
                </div>
            </td>
        </tr>
            <td>
                <h4><a href="job_detail.html">Ziab u Nisa</a></h4>
            </td>
            <td>
                <div class="col-xs-2">
                    <input type="text" placeholder="Grade" class="grade">
                </div>
            </td>
        </tr>
        </tr>
            <td>
                <h4><a href="job_detail.html">Raja M.Waleed</a></h4>
            </td>
            <td>
                <div class="col-xs-2">
                    <input type="text" placeholder="Grade" class="grade">
                </div>
            </td>
        </tr>
    </table>
</div>

java script code is  
<script>
    $($document).ready(function(){
    $("#std-list").hide();

    $("#cour").click( function(){
    $("#std-list").show();
    });
    });
    </script>

【问题讨论】:

  • 你的 jquery 代码在哪里?
  • HTML 不正确,不提供 jQuery。

标签: javascript php jquery laravel


【解决方案1】:

$(document).ready(function(){
    $("#hide").click(function(){
        $("p").hide(1000);
    });
    $("#show").click(function(){
        $("p").show(1000);
    });
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>

<p>If you click on the "Hide" button,<br> I will disappear.</p>

<button id="hide">Hide</button>
<button id="show">Show</button>

【讨论】:

    【解决方案2】:

    根据我的理解,下面的代码。请查收,希望对你有帮助。。

        $(document).ready(function(){
             $('.custom-select').change(function(){
              if($(".custom-select option:selected").index() == 1){
                 $('#std-list').show();          
              }else{
                 $('#std-list').hide();
              }
             });
        });
    

    【讨论】:

    • div 是隐藏的,但是当用户点击第一个选择选项 php developer #std-list 应该显示但它没有显示
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-03-11
    • 1970-01-01
    • 2016-01-24
    • 1970-01-01
    • 2011-11-06
    相关资源
    最近更新 更多