为什么我在分号上出现语法错误?

时间:2011-02-20 15:33:25

标签: javascript jquery syntax flickr

这段代码不会产生任何错误:

//if the image has tags
if(data.photo.tags.tag != '') {

    //create an empty array to contain all the tags
    var tagsArr = new Array();

    //for each tag, run this function
    $.each(data.photo.tags.tag, function(j, item){

        //push each tag into the empty 'tagsArr' created above
        tagsArr.push('<a href="http://www.flickr.com/photos/tags/' + item._content + '">' + item.raw + '</a>');

    });

    //turn the tags array into a string variable
    //var tags = tagsArr.join(' ');
}

但如果我将tags数组推送行更改为:

//push each tag into the empty 'tagsArr' created above
    tagsArr.push( + item.raw + );                                    
});

然后我在分号上出现语法错误。我想要做的是删除标记的链接,只返回原始链接。

思考&amp;谢谢!

1 个答案:

答案 0 :(得分:2)

如果您只想输出item.raw值,请执行:

tagsArr.push(item.raw);