Jquery 在第二行插入元素
如何使函数在每秒输出后显示我的行“仅每秒输出”Jquery 在第二行插入元素,jquery,function,Jquery,Function,如何使函数在每秒输出后显示我的行“仅每秒输出” $.get(dataurl + '?service=plug1&device1=' + device1 + '&device2=' + device2 + '', function(d){ var myText = '' $(d).find('plug').each(function(){ myText += 'every output' myText += 'only every s
$.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'
});
)
您可以使用索引:
$(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) {
...
});
效验如神谢谢:)