简体   繁体   中英

JQuery each: Pause & Continue iteration after a click

$.getJSON('http://example.com', function(data) {

  $.each(data.songs, function(index, song) { 

    //Paused & waiting for a click

    $("#next").click(function() {
         alert("Processing the next object...");
    });

 });

I would that JQuery analyze the next object only after the user click on #next element.

I don't need a "timeout", just user action to go to the next object

Probably not with an each loop. You'd be better having your click function capture clicks and process an item from the list of items based on a pointer you set. So something like this:

var jsonData = "";
var pointer = 0;
$.getJSON('http://example.com', function(data) {
    jsonData = data;
};
$("#next").click(function() {
    //process item described by pointer
    pointer = pointer + 1;
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM