문제

I am trying to figure out the method for switching audio tag source. In this example I am getting the source from a list, however I'm not sure how to do it.

Here is the fiddle: jsfiddle.net/4vrR2/9

Any advice on making it work would be appreciated :)

도움이 되었습니까?

해결책

To change the attribute you need to specify setAttribute("src",value) instead of src:

http://jsbin.com/zexoweyu/1/edit

function changeSong() {
  var element = document.getElementById("audioPlayer") 
  element.setAttribute("src","magic");
}

PS: To see the change in the DOM open the browser devtools, since JSBin will not reflect the change in the source code tab.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top