gpt4 book ai didi

jquery - 如何将CSS箭头插入html页面并使其可点击

转载 作者:行者123 更新时间:2023-11-28 10:59:42 26 4
gpt4 key购买 nike

大家好,我正在为我大学的一个元素制作一个常见问题解答页面,一切正常,但我想让它看起来更漂亮。我在 css 文件中做了一个箭头,我想把它放到我的 html 中。在我的 html 中,标题有一个显示和隐藏内容的按钮,这要归功于 jQuery。我的问题是:如何将箭头放在每个标题中并使其可点击,以便我可以删除按钮并通过单击标题自行显示内容?

谢谢你的帮助

这是我的 CSS:

    <!DOCTYPE html>
<html>
<head>
<style>
.body
{
padding: 10px 6px;
height: 0;
background: #ff4400;
display:inline-block;
margin:0 0 0 -4px;
z-index:999;
}

.arrow
{
width: 0px;
height: 0px;
border-style: solid;
border-width: 10px 0 10px 15px;
border-color: transparent transparent transparent #ff4400;
display: inline-block;
margin: 0 0 0 -5px;
}

</style>
</head>

<body>

<div class="body"></div>
<div class="arrow"></div>

</body>
</html>

这是我的html文件

    <!DOCTYPE html>
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js">
</script>
<script>
$(document).ready(function(){
$(".button").click(function () {
var div= $("#"+this.value);
div.toggle("slow").siblings().hide("slow");
});
});
</script>
</head>
<body>
<title>FAQ</title>
<h><font size="7">FAQ</font><font size= "5.5">Most frequently asked questions</font></h>
<div id="buttonDiv"></div>

<!-- setting BUTTON 1-->
<h1><font size="5">QUESTION 1</font><button id="button1" type="button" class="button" value="Show1">Show/Hide</button></h1>
<!--------------------QUESTION 1 --------------------------------------------->

<div>
<div id="Show1" style="display:none">
Answer to the question 1
</div>
</div>


</body>
</html>

最佳答案

JS:

$(document).ready(function(){
$(".button").click(function () {
var div= $("#"+this.name);
div.toggle("slow").siblings().hide("slow");
});
});

HTML:

<h1>
<div class="arrow"></div>

<a class="button" name="Show1" href="#">
<font size="5">QUESTION 1</font>
</a>
</h1>

<div id="Show1" style="display:none">
Answer to the question 1
</div>

演示: http://jsfiddle.net/788NK/6/

希望是你所需要的。

关于jquery - 如何将CSS箭头插入html页面并使其可点击,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22510948/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com