例子12:Ajax加载美女图片(jQuery)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<button id="ok">换一组</button>
<div id="container"></div>
<script src="js/jquery.min.js"></script>
<script>
$(function() {
$('#ok').on('click', function() {
var url = 'http://api.tianapi.com/meinv/?key=772a81a51ae5c780251b1f98ea431b84&num=10';
$.getJSON(url, function(jsonObj) {
$('#container').empty();
$.each(jsonObj.newslist, function(index, mm) {
$('#container').append(
$('<img>').attr('width', '250').attr('src', mm.picUrl)
);
});
});
});
});
</script>
</body>
</html>