音频标签无法在html5页面中解析

时间:2012-06-15 23:51:06

标签: html5

我将此JS页面链接到XML所有元素都是视图,但xml文件中的音频标签不是html5页面中的视图..任何建议如何使此功能检索音频文件并将其显示为html5 audi播放器。

init: function () {

    //jQuery ajax call to retrieve the XML file
    $.ajax({
        type: "GET",
        url: XMLLIST.xml,
        dataType: "xml",            
        success: XMLLIST.parseXML
    }); 

}, // end: init()

parseXML: function (xml) {

    //Grab every single ITEM tags in the XML file
    var data = $('item', xml).get();
    //Allow user to toggle display randomly or vice versa
    var list = (XMLLIST.random) ? XMLLIST.randomize(data) : data;
    var i = 1;

    //Loop through all the ITEMs
    $(list).each(function () {

        //Parse data and embed it with HTML
        XMLLIST.insertHTML($(this));            

        //If it reached user predefined total of display item, stop the loop, job done.
        if (i == XMLLIST.display) return false;
        i++;
    });


}, // end: parseXML()

insertHTML: function (item) {

    //retrieve each of the data field from ITEM
    var url = item.find('url').text();
    var image = item.find('image').text();
    var audio=item.find('audio').text();
    var title = item.find('title').text();
    var desc = item.find('desc').text();
    var html;

    //Embed them into HTML code
    html = '<div class="item">';
    html += '<a href="' + url + '"><image"' + image + '" alt="' + title + '" />';

    html += '<span>' + title + '</span></a>';
    html += '<audio control="control"><span> ' +audio+' </span></audio>';
    html += '<p>' + desc + '</p>';
    html += '</div>';

    //Append it to user predefined element
    $(html).appendTo(XMLLIST.appendTo);

}, // end: insertHTML()


randomize: function(arr) {

    //randomize the data
    //Credit to JSFromHell http://jsfromhell.com/array/shuffle
    for(var j, x, i = arr.length; i; j = parseInt(Math.random() * i), x = arr[--i], arr[i] = arr[j], arr[j] = x);
        return arr;

} // end: randomize()    

}

1 个答案:

答案 0 :(得分:0)

AFAIK .each()用于遍历jQuery对象,如果要迭代数组,请使用$.each()

你有

$(list).each(function () {

应该是

$.each(list, function () {

因为list是dom节点的数组而不是jQuery对象