如果定义了jQuery追加

时间:2013-04-21 15:38:58

标签: javascript jquery

如果电话存在,我将如何进行此附加,如果电话不存在则跳过

for (var i in data.businesses) {
    $('body').append( "<p>" + data.businesses[i].telephone + "</p>");
}

3 个答案:

答案 0 :(得分:1)

尝试

$.each(data.businesses, function(index, business){
    if(business.telephone){
        $('body').append( "<p>" + business.telephone + "</p>");
    }
});

答案 1 :(得分:1)

for (var i in data.businesses) {
    if(data.businesses[i].telephone)
        $('body').append( "<p>" + data.businesses[i].telephone + "</p>");
 }

答案 2 :(得分:0)

试试这个:

for (var i in data.businesses) {
    if(data.businesses[i].telephone  !== null and data.businesses[i].telephone !== undefined) {
        $('body').append( "<p>" + data.businesses[i].telephone + "</p>");
    }
}