[英]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>
基本上,我有一個按鈕的代碼。 我如何添加一個功能,在隱藏控制器的情況下開始播放音樂,並在播放音樂的同時將您發送到下一頁?
你必須先音頻源然后在按鈕上分配一個功能
<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>
然后在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.