這裏總的noob,試圖有條件地將一些值附加到一個html對象。這是從我發現的示例代碼構建的,所以請親切...在jQuery中附加條件語句append
$.getJSON('url to facebook json feed', function(fbresults){
$.each(fbresults.data, function(){
$('<div></div>')
.append('<h1>' + this.from.name + '</h1>')
.append('<p>' + this.story + '</p>')
$if (typeof this.picture !== "undefined") {
.append('<img src="' + this.picture + '">')};
.appendTo('#facebook')
});
});
來吧,沒有什麼像'$ if' ...嘗試分離每個附加命令,然後添加條件,其中一些。 – roomcays 2013-03-03 22:58:03