Javascript jQuery accordion()不工作
我的jQuery手风琴无法处理HTML段落。我哪里出错了 simple.htmlJavascript jQuery accordion()不工作,javascript,jquery,html,jquery-ui,Javascript,Jquery,Html,Jquery Ui,我的jQuery手风琴无法处理HTML段落。我哪里出错了 simple.html 两个问题:您没有包括jQueryUICSS,您的脚本也必须包括在内。使用以下命令: <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"&
两个问题:您没有包括jQueryUICSS,您的脚本也必须包括在内。使用以下命令:
<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:这并不意味着什么,因为您的问题是在页面中包含jQuery+jQuery UI两个问题:您没有包含jQuery UI CSS,而且您的脚本必须包含在页面中。使用以下命令:
<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>
$(document).ready(function() {
$("#accordion").accordion();
});
并从页面底部删除脚本。Fiddle:这并不意味着什么,因为您的问题是在页面中包含jQuery+jQuery UI
$(document).ready(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>
把这个放在头牌上
<script>
$(document).on('ready', function(){
$("#accordion").accordion();
});
</script>
看这个用这个
<!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>
把这个放在头牌上
<script>
$(document).on('ready', function(){
$("#accordion").accordion();
});
</script>
看到这个尽管我在单独的脚本块中添加了window.load调用,但我还是按照提供的代码进行了尝试,并且工作正常。正如其他人所指出的,您应该将手风琴代码放入“文档就绪”侦听器中。它不工作,或者看起来很奇怪-因为没有CSS文件,它看起来很奇怪,但仍然可以工作。什么不起作用?最好使用$document.ready,因为它不会等待图像等外部资源加载。这不会有太大的区别,但您最好保持一致,因为您使用的是jQuery。+1感谢您的回复。当我单击链接(例如,第一句的标题)时,标题下的句子不会消失或重新出现。我尝试了您提供的代码,尽管我在单独的脚本块中添加了window.load调用,并且它按预期工作。正如其他人所指出的,您应该将手风琴代码放入“文档就绪”侦听器中。它不工作,或者看起来很奇怪-因为没有CSS文件,它看起来很奇怪,但仍然可以工作。什么不起作用?最好使用$document.ready,因为它不会等待图像等外部资源加载。这不会有太大的区别,但您最好保持一致,因为您使用的是jQuery。+1感谢您的回复。当我点击链接时,例如,第一句的标题,标题下的句子不会消失或重新出现。对我的帖子投了否决票的用户请告诉我为什么?对我的帖子投了否决票的用户请告诉我为什么?