gpt4 book ai didi

javascript - HTML - 如何通过按下按钮使文本消失并显示不同的文本?

转载 作者:行者123 更新时间:2023-12-02 15:00:08 25 4
gpt4 key购买 nike

所以我试图在这个网站上制作这个小小的“选择游戏”。

http://puu.sh/ncAr8/be095ee6e2.png

我已经做到了这一点,但是...当您单击“确定”时,它会将您带到另一个页面。我不想那样做。

相反,当您单击“确定”时,我希望文本和按钮消失并显示不同的文本/按钮。

这是我的代码。请原谅我糟糕的 HTML,我没那么优秀。

<!DOCTYPE html>
<html>
<head>
<meta name="theme-color" content="#18191b">
<link rel="icon" sizes="192x192" href="assets/trans.gif">
<title>...</title>
</head>


<div class="audio">
<audio autoplay="true" src="assets/Virtual Campfire with Crackling Fire Sounds (HD).mp3"/>
</div>


<div id="test">
<center><h1 class="center2">Do you want to join the campfire?<br> There is one person there... looking sad.</h1></center>
</div>
<center><a href="join1.html" class="center3">Sure.</a></center>


<div id="test">
<center><img class="center" src="assets/trans.gif"/></center>
</div>

<style>
img.center {
background-repeat: no-repeat;
background-attachment: fixed;
background-position: center;
display:block;
position: relative;
top: 200px;
}
h1.center2 {
margin: auto;
width: 60%;
padding: 10px;
color: white;
font-family: "Myriad Pro";
text-align: center;
top: 70px;
position: relative;
}
a.center3 {
margin: auto;
width: 60%;
padding: 10px;
color: white;
font-family: "Calibri Light";
text-align: center;
top: 80px;
position: relative;
font-size: 25px;
color: #EEB300;
}
#test h1 {
margin-top: 25px;
font-size: 45px;
text-align: center;

-webkit-animation: fadein 2s; /* Safari, Chrome and Opera > 12.1 */
-moz-animation: fadein 2s; /* Firefox < 16 */
-ms-animation: fadein 2s; /* Internet Explorer */
-o-animation: fadein 2s; /* Opera < 12.1 */
animation: fadein 2s;
}

@keyframes fadein {
from { opacity: 0; }
to { opacity: 1; }
}

/* Firefox < 16 */
@-moz-keyframes fadein {
from { opacity: 0; }
to { opacity: 1; }
}

/* Safari, Chrome and Opera > 12.1 */
@-webkit-keyframes fadein {
from { opacity: 0; }
to { opacity: 1; }
}

/* Internet Explorer */
@-ms-keyframes fadein {
from { opacity: 0; }
to { opacity: 1; }
}

/* Opera < 12.1 */
@-o-keyframes fadein {
from { opacity: 0; }
to { opacity: 1; }
}
</style>

<body style="background-color:#18191b">
</body>

</html>

请帮助我,我不太擅长 HTML,也希望得到一些建议。谢谢!

最佳答案

我已经根据您的代码创建了一个工作示例。您可以在 http://codepen.io/imanik/pen/bEyVpj

之前在此处查看

$("#confirm-btn").on("click", function() {
$(this).hide();
$("#test").hide();
$("#another").fadeIn("slow");
return false;
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<!DOCTYPE html>
<html>

<head>
<meta name="theme-color" content="#18191b">
<link rel="icon" sizes="192x192" href="assets/trans.gif">
<title>...</title>
</head>


<div class="audio">
<audio autoplay="true" src="assets/Virtual Campfire with Crackling Fire Sounds (HD).mp3" />
</div>


<div id="test">
<center>
<h1 class="center2">Do you want to join the campfire?<br> There is one person there... looking sad.</h1>
</center>
</div>
<div id="another" style="display:none;">
<center>
<h1 class="center2">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Aspernatur sit doloribus officiis praesentium assumenda, quod eaque illum voluptatem voluptatum distinctio.</h1>
</center>
</div>
<center><a href="join1.html" class="center3" id="confirm-btn">Sure.</a>
</center>


<div id="test">
<center>
<img class="center" src="assets/trans.gif" />
</center>
</div>

<style>
img.center {
background-repeat: no-repeat;
background-attachment: fixed;
background-position: center;
display: block;
position: relative;
top: 200px;
}
h1.center2 {
margin: auto;
width: 60%;
padding: 10px;
color: white;
font-family: "Myriad Pro";
text-align: center;
top: 70px;
position: relative;
}
a.center3 {
margin: auto;
width: 60%;
padding: 10px;
color: white;
font-family: "Calibri Light";
text-align: center;
top: 80px;
position: relative;
font-size: 25px;
color: #EEB300;
}
#test h1 {
margin-top: 25px;
font-size: 45px;
text-align: center;
-webkit-animation: fadein 2s;
/* Safari, Chrome and Opera > 12.1 */
-moz-animation: fadein 2s;
/* Firefox < 16 */
-ms-animation: fadein 2s;
/* Internet Explorer */
-o-animation: fadein 2s;
/* Opera < 12.1 */
animation: fadein 2s;
}
@keyframes fadein {
from {
opacity: 0;
}
to {
opacity: 1;
}
}
/* Firefox < 16 */
@-moz-keyframes fadein {
from {
opacity: 0;
}
to {
opacity: 1;
}
}
/* Safari, Chrome and Opera > 12.1 */
@-webkit-keyframes fadein {
from {
opacity: 0;
}
to {
opacity: 1;
}
}
/* Internet Explorer */
@-ms-keyframes fadein {
from {
opacity: 0;
}
to {
opacity: 1;
}
}
/* Opera < 12.1 */
@-o-keyframes fadein {
from {
opacity: 0;
}
to {
opacity: 1;
}
}
</style>

<body style="background-color:#18191b">
</body>

</html>

其工作方式是将 CSS 显示属性设置为 none,以便将隐藏的内容隐藏起来。

然后使用 Jquery 定位按钮并监听单击事件。当发生这种情况时,只需隐藏您想要隐藏的所有元素并显示其可见的元素即可。

关于javascript - HTML - 如何通过按下按钮使文本消失并显示不同的文本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35487485/

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