如何在页面加载时打开一个Accordin By Default

时间:2017-08-08 05:18:12

标签: javascript jquery html html5 accordion

我在我的移动网站上使用以下代码,选择Accordin会显示其内容。我想加载第一个Accordin来加载并在用户加载页面时默认显示。我怎样才能实现那一个。

这是Html文件

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="http://www.jqueryscript.net/css/jquerysctipttop.css" 
rel="stylesheet" type="text/css">
<style>
        body {
        font-family: 'Roboto', sans-serif;
  background-color:#fafafa;
    }
    .container {
        max-width: 960px;
        margin: 150px auto;
    }
    h3 {
        font-weight: normal;
        font-size: 16px;
    }
</style>

<link href="src/ziehharmonika.css" rel="stylesheet" type="text/css">
</head>

<body>

    <div class="ziehharmonika">
        <h3>Section One</h3>
        <div>
            <iframe src="http://cdn.wonderfulengineering.com/wp-content/uploads/2016/01/Desktop-Wallpaper-5.jpg" height="600px" width="100%"></iframe>
        </div>
        <h3>Section Two</h3>
        <div>
            <iframe src="http://cdn.wonderfulengineering.com/wp-content/uploads/2016/01/Desktop-Wallpaper-5.jpg" height="600px" width="100%"></iframe>
        </div>
        <h3>Section Three</h3>
        <div>
            <iframe src="http://cdn.wonderfulengineering.com/wp-content/uploads/2016/01/Desktop-Wallpaper-5.jpg" height="600px" width="100%"></iframe>
        </div>
    </div>

这是脚本文件

<script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
<script src="src/ziehharmonika.js"></script>
<script>
$(document).ready(function() {
    $('.ziehharmonika').ziehharmonika({
        collapsible: true,
        prefix: '★'
    });
});
</script>
<script type="text/javascript">

 var _gaq = _gaq || [];
 _ gaq.push(['_setAccount', 'UA-36251023-1']);
  _gaq.push(['_setDomainName', 'jqueryscript.net']);
  _gaq.push(['_trackPageview']);

  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();

任何帮助都会受到很多赞赏。

1 个答案:

答案 0 :(得分:0)

使用JSfiddle创建在线版本会更好。

试试这个:

 <div class="ziehharmonika">
    <h3 class="active">Section One</h3>
    <div style="display:block;">
        <iframe src="http://cdn.wonderfulengineering.com/wp-content/uploads/2016/01/Desktop-Wallpaper-5.jpg" height="600px" width="100%"></iframe>
    </div>
    <h3>Section Two</h3>
    <div>
        <iframe src="http://cdn.wonderfulengineering.com/wp-content/uploads/2016/01/Desktop-Wallpaper-5.jpg" height="600px" width="100%"></iframe>
    </div>
    <h3>Section Three</h3>
    <div>
        <iframe src="http://cdn.wonderfulengineering.com/wp-content/uploads/2016/01/Desktop-Wallpaper-5.jpg" height="600px" width="100%"></iframe>
    </div>
</div>