jQuery accordion() not working
jQuery accordion() not working
我的jQuery accordion()不能在我的HTML段落上工作。我哪里做错了?
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();
};
用这个…
<!DOCTYPE html>
<html>
<head>
<title></title>
<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>
</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>
</body>
把这个放到head标签
<script>
$(document).on('ready', function(){
$("#accordion").accordion();
});
</script>
看jsFiddle的例子
两个问题:你不包括jQuery UI CSS,你的脚本必须包括你的<head>
。使用:
<head>
<title>My Title</title>
<link href="http://code.jquery.com/ui/1.10.2/themes/smoothness/jquery-ui.css" rel="stylesheet" type="text/css">
<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript" src="http://code.jquery.com/ui/1.10.2/jquery-ui.js"></script>
<script>$(document).ready(function(){ $( "#accordion" ).accordion(); });</script>
</head>
并从页面底部删除脚本。
Fiddle: http://jsfiddle.net/cxJW6/(这并不意味着太多,因为你的问题是包括jQuery+jQuery UI在你的页面)
$(document).ready(function() {
$("#accordion").accordion();
});
相关文章:
- $rootScope not working
- jQuery document.ready not working
- Javascript getElementsByTagName not working?
- JQuery.val( ) not working
- Tomcat websocket is not working
- Javascript JSON.parse not working
- NodeJS Multer is not working
- Regex not working
- Ember run.debounce not working
- AngularJs 1 not working
- document.getElementById.style.backgroundImage not working
- Rxjs5, distinct() is not working
- createOscillator noteOn not working
- Javascript - .getHours() not working
- Javascript setTimeout not working | onkeydown
- MongoDB $pull not working
- Express router.use not working
- JSONP not working
- window.opener not working in chrome & IE
- Backbone + RequireJS: Collection.each() is not working