2013-04-24 63 views
0

如何在每次輸出後顯示我的行「只有每秒輸出」?在第二行插入元素

$.get(dataurl + '?service=plug1&device1=' + device1 + '&device2=' + device2 + '', function(d){ 
    var myText = '' 
    $(d).find('plug').each(function(){ 
     myText += 'every output' 
     myText += 'only every second output' 
    }); 
) 

回答

2

你可以使用索引:

$(d).find('plug').each(function(i) { 
    myText += 'every output' 

    if (i % 2 == 0) { 
     myText += 'only every second output' 
    } 
}); 

另外,不要手動構建您的查詢字符串。它可能無法正常逃生,而替代方式看起來更好:

$.get(dataUrl, { 
    service: plug1, 
    device1: device1, 
    device2: device2 
}, function(data) { 
    ... 
}); 
+0

工作就像一個魅力。謝謝 :) – 2013-04-24 07:38:04