开发者

jQuery storing settings

I'm trying to build a player for a radio station that automatically updates the current song from an XML file, the problem is that I don't want it to update the UI (updateSongIMG) unless the song has actually changed. I have a hidden div called settings_songid that stores the song id and it should check that against a value in the XML file, if its different, then it should update it. The problem is that the function below does not actually work, it pulls all the XML data fine, but it doesn't call updateSongIMG as it fails the 'if'.

function loadXML() {
    $.get('player.xml'开发者_运维技巧, function(d){
        $(d).find('onair').each(function(){
            var $onair = $(this); 

            var show_name = $onair.find('showname').text();
            var song_l1 = $onair.find('songline1').text(); 
            var song_l2 = $onair.find('songline2').text();  
            var song_img = $onair.find('songimg').text(); 

            var song_id = $onair.find('song_id').text(); 
            var old_song_id = $("#settings_songid").html();

            if (!old_show_id==show_id){
                $("#settings_songid").html(song_id);

                updateSongIMG(song_img,song_l1,song_l2);
            }
        });
    });
};
​


Where are these defined old_show_id and show_id ?!

You can use http://api.jquery.com/jQuery.data/ for that kind of stuff.


Try .text():

 var old_song_id = $("#settings_songid").text();

and your if clause is wrong. I think you mean song and not show:

if(old_song_id != song_id)

For storing arbitrary data, have a look at jQuery's .data() method. This much more convenient than storing data in a hidden div.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜