注意:在发布之后,您可能需要清除浏览器缓存才能看到所作出的变更的影响。
- Firefox或Safari:按住Shift的同时单击刷新,或按Ctrl-F5或Ctrl-R(Mac为⌘-R)
- Google Chrome:按Ctrl-Shift-R(Mac为⌘-Shift-R)
- Internet Explorer或Edge:按住Ctrl的同时单击刷新,或按Ctrl-F5
- Opera:按 Ctrl-F5。
function addSound(){
var c = 0
$('.word_entries_container').each(function(){
btn = $('<button id="soundBtn-'+c+'" class="sound_button" style="display:inline-block;">'
+' <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor"'
+' class="bi bi-play-circle" viewBox="0 0 16 16">'
+'<path d="M8 15A7 7 0 1 1 8 1a7 7 0 0 1 0 14zm0 1A8 8 0 1 0 8 0a8 8 0 0 0 0 16z"/>'
+'<path d="M6.271 5.055a.5.5 0 0 1 .52.038l3.5 2.5a.5.5 0 0 1 0 .814l-3.5 2.5A.5.5 0 0 1 6 10.5v-5a.5.5 0 0 1 .271-.445z"/>'
+'</svg></button>')
var en = $(this).children('.sub_container').children('.word_name').children('.word_en').text()
console.log(en)
$('<audio src="https://dict.youdao.com/dictvoice?audio='+en+'" id=sound-"'+c+'" controls="controls" hidden="true">').appendTo($(this))
$(this).children('.sub_container').children('.sound').append(btn)
$('#soundBtn-'+c).bind("click",function (){
autoPlay('sound-'+c)
console.log('sound-'+c)
})
c+=1
})
}
function autoPlay(id) {
var myAuto = document.getElementById(id);
myAuto.play();
}
addSound()