我看过其他的主题,但他们的代码真的很复杂。我希望我的文章很简单,这样我就可以很容易地理解它。我原以为这很容易,但结果却很难。显然,你不能通过改变它的属性来改变音频源。我希望音频源在复选框更改时更改,然后它将更改为相应的音频文件。
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.
}我不确定为什么它不能工作。谁来帮帮我!
发布于 2017-04-18 10:32:02
"#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.
}https://stackoverflow.com/questions/43462188
复制相似问题