[英]Need help adding functions to a button in html
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<style>
.in-middle {
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
}
.button {
border-radius: 50%;
background-color: red;
color: white;
}
</style>
</head>
<body>
<div class="in-middle">
<button class="button">
click me
</button>
</div>
</body>
</html>
Basically, i have this code for a button.基本上,我有一个按钮的代码。 How do i add a function that starts playing music with the controller hidden, and sends you to next page while still playing the music?
我如何添加一个功能,在隐藏控制器的情况下开始播放音乐,并在播放音乐的同时将您发送到下一页?
you have to audio source first then assign a function on the button你必须先音频源然后在按钮上分配一个功能
<audio id="myAudio">
<source src="horse.ogg" type="audio/ogg">
</audio>
<div id="controler">
</div>
<div class="in-middle">
<button class="button" onclick="myfunction">
click me
</button>
</div>
then add the function on the js file然后在js文件中添加函数
function myfunction(){
document.getElementById("myAudio").play(); //it will start the audio
document.getElementById("controler").style.display="none" // it will hide your controller
window.location.href="pageurl"; // this will open new window
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.