Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/maven/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery 在第二行插入元素_Jquery_Function - Fatal编程技术网

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) {
    ...
});

效验如神谢谢:)