gpt4 book ai didi

javascript - 无法更改音频源

转载 作者:行者123 更新时间:2023-12-03 01:46:12 25 4
gpt4 key购买 nike

我看过其他主题,但是它们的代码确实很复杂。我希望地雷很简单,所以我可以很容易地理解它。我认为这很容易,但事实证明这很困难。显然,您无法通过更改音频属性来更改音频源。我希望音频源在复选框已更改时更改,然后它将更改为相应的音频文件。

的HTML

<select id="ccw" onblur="check()">
<option>Lobby</option>
<option>Autumn</option>
<option>Winter</option>
<option>Spring</option>
<option>Summer</option>
</select>
<audio class="stage10" controls>
<source src="default.mp3" type="audio/mpeg">
Audio element not supported by your browser
</audio>

JS
var songs = [
//lobby
"default.mp3",
//autumn
"fall.mp3",
//winter
"the ice age.mp3",
//spring
"AHHHH ITS BEEEEEEEES.mp3",
//summer
"Da Summa of 1989 or was it 1998 i dont know.mp3"

//please do not take notes of the file's names
]

$(function() {
$('#ccw').on('change', check)
})
function check() {
var ccw = $('#ccw').val()
if (ccw == "Autumn") {
$('#stage10 source').attr('src', songs[1])
} else if (ccw == "Winter") {
$('#stage10 source').attr('src', songs[2])
} else if (ccw == "Spring") {
$('#stage10 source').attr('src', songs[3])
} else if (ccw == "Summer") {
$('#stage10 source').attr('src', songs[4])
} else {
$('#stage10 source').attr('src', songs[0])
}
$('audio')[10].load() // this wasn't here before, but i tried testing with it.
}

我不确定为什么它不起作用。有人请帮助我!

最佳答案

“#stage10”是一个ID选择器,如果要按类选择元素,请将其替换为“.stage10”:

function check() {
var ccw = $('#ccw').val()
if (ccw == "Autumn") {
$('.stage10 source').attr('src', songs[1])
} else if (ccw == "Winter") {
$('.stage10 source').attr('src', songs[2])
} else if (ccw == "Spring") {
$('.stage10 source').attr('src', songs[3])
} else if (ccw == "Summer") {
$('.stage10 source').attr('src', songs[4])
} else {
$('.stage10 source').attr('src', songs[0])
}
$('audio')[10].load() // this wasn't here before, but i tried testing with it.
}

关于javascript - 无法更改音频源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43462188/

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