我的jQuery手风琴()不适用于我的HTML段落。我哪里做错了?jQuery手风琴()不工作
simple.html
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<div id="mainContent">
<h1>This is an According Example</h1>
</div>
<div id="accordion">
<h3><a href="#">Heading for first sentence</a></h3>
<div>
<p>This is the first sentence.</p>
</div>
<h3><a href="#">Heading for second sentence</a></h3>
<div>
<p>This is the second sentence.</p>
</div>
<h3><a href="#">Heading for third sentence</a></h3>
<div>
<p>This is the third sentence.</p>
</div>
</div>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.10.2/jquery-ui.min.js"></script>
<script src="myscript.js"></script>
</body>
</html>
myscript.js
window.onload = function(){
$("#accordion").accordion();
};
我试着提供您的代码,虽然我在一个单独的脚本块中添加了window.load调用,并且按预期工作。您应该像其他人指出的那样,将手风琴代码放入“准备好文档”的监听器中。它不工作,还是看起来很奇怪 - 因为没有CSS文件,它看起来很奇怪,但仍然有效。 –
你的代码工作得很好 - http://jsfiddle.net/twgjW/。什么是“不工作”?使用'$(document).ready'是首选,因为它不会等待外部资源(如图像)加载。它不会有很大的不同,但是你可能会一直使用jQuery。 – Ian
+1感谢您的回复。当我点击链接(例如标题的第一句)时,标题下方的句子不会消失或重新出现。 – Anthony