document.getElementById()。src音频问题

时间:2014-04-23 10:59:53

标签: javascript html5 html5-audio getelementbyid src

我在这里做错了什么? (见JS小提琴:http://jsfiddle.net/55aJt/6/

<audio id="myAudio" src="" controls></audio>

对象

var allQuestions = [{
    question: "http://www.w3schools.com/html/horse.mp3",
    choices: ["3rd", "5th", "4th"],
    correctAnswer: 2
},

功能

function setHeader(questionNum) {
    var questionHeaderEl = document.getElementById("myAudio").src;
    questionHeaderEl.innerHTML = allQuestions[questionNum].question;
}

2 个答案:

答案 0 :(得分:0)

var questionHeaderEl = document.getElementById("myAudio").src;
questionHeaderEl.innerHTML = allQuestions[questionNum].question;   

使用上面的代码,您要为元素var值创建src,然后尝试更改innerHtml值的src。它应该是这样的:

var questionHeaderEl = document.getElementById("myAudio");
questionHeaderEl.src = allQuestions[questionNum].question;

答案 1 :(得分:0)

使用

questionHeaderEl.src 

而不是

questionHeaderEl.innerHTML