Javascript .accordion() 不工作

标签 javascript jquery css html

<分区>

我的网站上的 javascript 有问题: 感谢您的帮助,我的.mouseenter.mouseleave() 已经解决了,但是我的.accordion() 仍然无法正常工作。有什么想法吗?

这是我的代码:

HTML:

    <!DOCTYPE html>
<head>
    <!--Accordion is not working, mouseenter is only working in first product, header is not all the way to the left-->
    <meta charset="utf-8">
    <link rel="stylesheet" href="css/bootstrap-theme.css" />
    <link rel="stylesheet" href="css/bootstrap.css" />
    <link rel="stylesheet" href="js/bootstrap.js" />
    <link rel="stylesheet" href="js/carousel.js" />
    <link rel="stylesheet" type="text/css" href="shopping.css" />
    <link rel="stylesheet"                                                      href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery- ui.css">
    <script src="//code.jquery.com/jquery-1.10.2.js"></script>
    <script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
</head>
<header>
    <h4><mark>Student Project #5 H.B.</mark></h4></br>
    <h2>Premium Computer Supplies!</h2>
</header>
<body>
<!----------------------------------------------------------------->
    <div class="row" id="row">
        <!--<div class="col-sm-3">-->
            <!--Insert picture-->
            <img src="surface3.jpg" alt="Microsoft Surface">
            <!--Accordion heading-->
            <div class="accordion">
            <h4>Microsoft Surface Pro 3</h4>
                <!--Description and price-->
                <div>
                <p>Insert description for the product here</p>
                    <p>Starting at $999!</p>
                </div>
            </div>
        </div>
    </div>
<!----------------------------------------------------------------->
    <div class="row" id="row">
        <!--<div class="col-sm-3">-->
            <!--Insert picture-->
            <img src="surface3cover.jpg" alt="Microsoft Surface Type Cover">
            <!--Accordion heading-->
            <div id="accordion">
            <h4>Microsoft Surface Pro 3 Typer Cover</h4>
                <!--Description and price-->
                <div>
                <p>Insert description for the product here</p>
                    <p>Starting at $129!</p>
                </div>
            </div>
        </div>
    </div>
<!----------------------------------------------------------------->
    <div class="row" id="row">
        <!--<div class="col-sm-3">-->
            <!--Insert picture-->
            <img src="mabook.jpg" alt="Apple Macbook Pro Retina">
            <!--Accordion heading-->
            <div id="accordion">
            <h4>Macbook Pro Retina Display</h4>
                <!--Description and price-->
                <div>
                <p>Insert description for the product here</p>
                    <p>Starting at $999!</p>
                </div>
            </div>
        </div>
    </div>
<!----------------------------------------------------------------->
    <div class="row" id="row">
        <!--<div class="col-sm-3">-->
            <!--Insert picture-->
            <img src="superdrive.jpg" alt="Apple SurperDrive">
            <!--Accordion heading-->
            <div id="accordion">
            <h4>Apple SuperDrive</h4>
                <!--Description and price-->
                <div>
                <p>Insert description for the product here</p>
                    <p>Starting at $79!</p>
                </div>
            </div>
        </div>
    </div>
<!----------------------------------------------------------------->
    <div class="row" id="row">
        <!--<div class="col-sm-3">-->
            <!--Insert picture-->
            <img src="case1.jpg" alt="Laptop Case">
            <!--Accordion heading-->
            <div id="accordion">
            <h4>Laptop Case</h4>
                <!--Description and price-->
                <div>
                <p>Insert description for the product here</p>
                    <p>Starting at $39!</p>
                </div>
            </div>
        </div>
    </div>
<!----------------------------------------------------------------->
<script>
  $(function() {
    $( ".accordion" ).accordion();
  });

    $( ".row" ).mouseenter(function() {
        $(this).animate({ fontSize : 14 });
});

    $( ".row" ).mouseleave(function() {
        $(this).animate({ fontSize : 13 });
});
    </script>
</body>

CSS:

    img {
    width:300px;
    height:200px;
}
header{
    background-color: crimson;
    color:darkblue;
    padding-left: 0;/*why is this not working*/
    width:100%
}
body{
    width:80%;
    background-color: lightgray;
    font-size: 13;
    padding-left: 5%
}
#row{
    background-color: white;
    width:30%;
    padding-left: 5%;

最佳答案

多个元素不能有相同的ID。那么它就不会识别了,现在是吗?

在这些 Accordion 和行上使用类选择器,否则它只会找到第一个。

关于Javascript .accordion() 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30987224/

相关文章:

jQuery 模式不能按预期工作

css - Material (垂直)步进器

html - 只有 css 的两行布局

javascript - 以 Angular 添加样式

javascript - Angular 2 以编程方式绑定(bind) ngIf

javascript - 如何将对象数组中的 id 转换为 JavaScript 列表

html - 是显示 : none loaded by the browser? 的图像

javascript - Mozilla AFRAME a-frame 通过按钮单击而不是击键启动检查器

JavaScript 添加日期函数

javascript - 如何添加一个div作为另一个div的背景?