无法在jquery中运行隐藏函数

unable to run the hide function in jquery

本文关键字:运行 隐藏 函数 jquery      更新时间:2023-09-26

嗨,我是jquery新手,我正试图调整一下这个小提琴http://jsfiddle.net/handtrix/dzr521qs/但却无法做到。我想做的是点击提交按钮,这个弹出隐藏。这是我的代码隐藏它,但它不工作,我无法找出错误

 $("#hide-me").click(function(){
    $(".content").hide("slow", function(){
        console.log("scfzd");
        alert("The paragraph is now hidden");
    });
 });

我给提交按钮分配了id "#hide-me"。

工作小提琴

首先你必须添加类hide-me而不是id,因为你有多个submit按钮,你不能在同一个文档中重复id:

<button type="submit" class="btn btn-default btn-block hide-me">Submit</button>

第二次使用.popover('hide')隐藏popover内容:

$(document).on("click", ".hide-me", function() {
    $('.popover-markup>.trigger').popover('hide');
});

让你的代码在jquery ready事件,

<script>
    $( document ).ready(function() {
       $("#hide-me").click(function(){
           $(".content").hide("slow", function(){
               console.log("scfzd");
               alert("The paragraph is now hidden");
           });
       });   
    });
</script>

试试这个

$(document).on("mousedown", ".hide-me", function() {
    $('.popover-markup>.trigger').popover('hide');
});

it also Working .