.hide没有处理点击功能

时间:2018-06-05 06:23:48

标签: jquery

目前,我有这段代码:

$(document).ready(function() {
  $('.search a').click(function() {
    $('.search2').show();
  });
  $('.search-close').click(function() {
    $('.search2').hide();
  });
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="search2">
  <form method="get" class="search-form2" id="search-form2" action="search.php">
    <input class="search-input2" type="text" name="search_keywords" id="search-text2" value="" placeholder="Search..." autocomplete="off">
    <a href="#!" class="search-lose"><img src="new_assets/assets/images/closebtn.png"></a>
</div>

目的是打开弹出搜索框并使用按钮/图像关闭弹出窗口

1 个答案:

答案 0 :(得分:0)

试试这个,

&#13;
&#13;
$(document).ready(function(){
    $(".btn1").click(function(){
        $(".search2").hide();
    });
    $(".btn2").click(function(){
        $(".search2").show();
    });
});
&#13;
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
</head>
<body>
<button class="btn1">Hide</button>
<button class="btn2">Show</button>
</body>
<div class="search2">
  <form method="get" class="search-form2" id="search-form2" action="search.php">
    <input class="search-input2" type="text" name="search_keywords" id="search-text2" value="" placeholder="Search..." autocomplete="off">
    <a href="#!" class="search-lose"><img src=""></a>
    </form>
</div>
</html>
&#13;
&#13;
&#13;