onClick功能链接不工作

onClick Function for Link Not Working

本文关键字:工作 链接 功能 onClick      更新时间:2023-09-26

我是jQuery的初学者&JavaScript和黑客一直试图得到一个功能在我的网站上工作。

页面加载通过CSS隐藏的部分,并在用户点击链接时显示。我有它的工作,但在试图使它更可用以后的其他按钮,我试图把它变成一个功能,导致它打破。

$(".bed-breakfast-explore").hide();
$("#bed-breakfast-menu").hide();       
function discoverBedBreakfast() {    
    $(".bed-breakfast-explore").slideToggle("slow");
    $(".hotel").css("display", "none");
    $(".resort").css("display", "none");
    $(".guest-house").css("display", "none");
    $("#bed-breakfast-menu").show();        
    $('html, body').animate({ 'scrollTop': $('#bed-breakfast-menu').offset().top - 86}, 1300);
}   

链接的HTML格式为:

<a class="button" href="#" onclick="discoverBedBreakfast()">Explore</a>

放置

<head>
    <script src="jquery-2.1.4.min.js"></script>
    <script >
    $(document).ready(function(){

    $(".bed-breakfast-explore").hide();
    $("#bed-breakfast-menu").hide();
    })

    function discoverBedBreakfast() {    
        $(".bed-breakfast-explore").slideToggle("slow");
        $(".hotel").css("display", "none");
        $(".resort").css("display", "none");
        $(".guest-house").css("display", "none");
        $("#bed-breakfast-menu").show();        
        $('html, body').animate({ 'scrollTop': $('#bed-breakfast-menu').offset().top - 86}, 1300);
    }
    </script>
</head>