0

我有一个问题我正在使用此代码来编辑图像 src 的那是创建 js,但它不工作......(单击按钮 jquery 创建对象然后此函数将更改此创建的对象中的 src)

该代码首先创建对象,第二个将编辑图像 src

function addToplaylist(title)
    {
       /* some CODE */

                var each = playlistts.join('</span><li><img class="plimg" src="/img/cover.png"><span  onclick="playinToplaylist($(this).html());" class="titletrack">');
                 $("#playlist").html('<li><img onload="this.src = \'/img/playlist/\'+$(this).next(\'span.titletrack\').text()+\'.jpg\'" src="/img/cover.png"><span  onclick="playinToplaylist($(this).html());" class="titletrack">' + each);

/* some CODE */

    }


    $(document).ready(function(){   
        $("body .plimg").attr("src",

        function (index) {
    var title = $(this).next('span.titletrack').text();
            var array = title.split(' - ');
            var track = array[0];
            var artist = array[1];

            var output;

            $.ajax({ //instead of getJSON as the function does not allow configurations.
                url: "http://ws.audioscrobbler.com/2.0/?method=track.search",
                data: {
                    track: track,
                    artist: artist,
                    api_key: "ca86a16ce762065a423e20381ccfcdf0",
                    format: "json",
                    lang: "en",
                    limit: 1
                },
                async: false, //making the call synchronous
                dataType: 'json', //specifying JSON type
                success: function (data) {
                    output = data.results.trackmatches.track.image[0]["#text"];
                }

            });
            return output;
        });
    });
4

0 回答 0