我正在尝试使用我在这里找到的切换代码:http://jsfiddle.net/wGbh5/。它看起来非常直截了当,完全按照我的意愿去做。
因此,我的style.css文件中有以下代码:
.clickme {
background-color: #eee;
border-radius: 4px;
color: #666;
display: block;
margin-bottom: 5px;
padding: 5px 10px;
text-decoration: none;}
.clickme:hover {
text-decoration: underline;
}然后,我创建了一个包含以下代码的toggle.js文件:
// Hide all the elements in the DOM that have a class of "box"
$('.box').hide();
// Make sure all the elements with a class of "clickme" are visible and bound
// with a click event to toggle the "box" state
$('.clickme').each(function() {
$(this).show(0).on('click', function(e) {
// This is only needed if your using an anchor to target the "box" elements
e.preventDefault();
// Find the next "box" element in the DOM
$(this).next('.box').slideToggle('fast');
});
});我在html中使用头调用两个文件,并使用以下行
<link rel="stylesheet" href="http://localhost:8888/kirby/assets/styles/styles.css" />
<script src="http://localhost:8888/kirby/assets/js/toggle.js"></script>正如您在链接中所看到的,我正在本地使用MAMP并试用CMS 柯比。
在HTML文件中,代码如下所示:
<a href="#" class="clickme">Click Me</a>
<div class="box">
Lorem Ipsum is simply dummy text of the printing and typesetting industry.
Lorem Ipsum has been the industry's standard dummy text ever since the 1500s,
when an unknown printer took a galley of type and scrambled it to make a type
</div>问题是,当我在浏览器中加载html文件时,它不能工作(如果它正常工作,我就会在这里)。"clickme“和"box”内容都会显示,当我单击它们时,没有任何附加内容。
有人能帮我解决我的问题吗?
提前谢谢
发布于 2017-10-06 10:19:53
问题在于您调用css和js文件的方式。使用kirby调用css文件的正确方法是css。
<?php echo css('assets/styles/styles.css') ?> 对于js来说
<?php echo js('assets/js/toogle.js') ?>https://stackoverflow.com/questions/15172562
复制相似问题