-1
<html>
<head>
<script src="js/jquery.min.js"></script>
<style>
button {padding: 20px;}
</style>
<script>
$(document).ready(function() {
var app = {
start: function() {
/* do something */
var obj = [{
"id": 0,
"firstname": "John",
"lastname": "Doe",
"email": "[email protected]"
}, {
"id": 1,
"firstname": "Mary",
"lastname": "Smith",
"email": "[email protected]"
}, {
"id": 2,
"firstname": "Paul",
"lastname": "Frances",
"email": "[email protected]"
}, {
"id": 3,
"firstname": "Frances",
"lastname": "Paul",
"email": "[email protected]"
}, {
"id": 4,
"firstname": "Alex",
"lastname": "Paul",
"email": "[email protected]"
}, {
"id": 5,
"firstname": "Harold",
"lastname": "Miller",
"email": "[email protected]"
}, {
"id": 6,
"firstname": "Trina",
"lastname": "Torres",
"email": "[email protected]"
}, {
"id": 7,
"firstname": "Alice",
"lastname": "Rogers",
"email": "[email protected]"
}, {
"id": 8,
"firstname": "Beth",
"lastname": "Peters",
"email": "[email protected]"
}];
console.log('obj: ', obj)
$.each(obj, function(index, item) {
$('.test')
.append(item.email + '</h3>')
.append(item.firstname + '<br/>')
.append(item.lastname + '<br/>')
console.log('Index' + index);
if (index === 4) {
nextIndex = index + 1;
return false;
console.log('Next Index: ' + nextIndex);
};
});
$('.load-data').click(function() {
$.each(obj, function(nextIndex, item) {
console.log('nextIndex: ' + nextIndex);
$('.test')
.append(item.email + '</h3>')
.append(item.firstname + '<br/>')
.append(item.lastname + '<br/>')
//console.log('Index' +nextIndex);
});
});
}
};
app.start();
});
</script>
</head>
<body>
<div class="test"></div>
<button class="load-data">Load More</button>
</body>
</html>
你想讓我們把所有的代碼放到一些小提琴裏面嗎? –
不要害羞,用幾句話解釋你的問題。 –
當然,如果你可以 –