<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>FAQ Section</title>
<link rel="stylesheet" type="text/css" href="styles.css"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("h2").click(function(){
$("p").toggle("fast");
});
}); </script>
</head>
<body>
<h1>FAQ</h1>
<div>
<!-- The FAQs are inserted here -->
<h2>Question1?</h2>
<p>Answer...</p>
<h2>Question2?</h2>
<p>Answer...</p>
<h2>Question3?</h2>
<p>Answer...</p>
</div>
</body>
</html>
这是我的示例页面:http://www.kursatkarabulut.com/kopya.htmljquery切换如何使用个人元素没有个人ID?
我试图做的是对我个人网站的常见问题页面。将会有大约40个问题。我是jQuery的新手。我用每个问题的切换。只有问题会在开始时显示,当用户点击一个问题时,它会显示在下面,再次点击它会隐藏。现在,当我点击一个问题时,它会展开并收缩所有问题。
有没有办法单独做到这一点,而不使用每个标题的个人ID? 以及如何加载页面切换关闭?
谢谢。
你可以做到这一点,但它会更容易重组代码位 – Huangism