[jQuery]ºñµ¿±âÀûÀ¸·Î JSONÆÄÀÏ ·Îµå |
|
|
|
8³â Àü |
// 02.jQuery.getJSON.js
[
{
"Num": "1",
"Name": "È«±æµ¿"
},
{
"Num": "2",
"Name": "¹éµÎ»ê"
},
{
"Num": "3",
"Name": "ÇѶó»ê"
}
]
// ----------------------------------------
<script src="../js/jquery-1.3.2-vsdoc2.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function () {
$("#btn .btnLoad").click(function () {
$.getJSON("02.jQuery.getJSON.js", function (data) {
$('#pnlDisplay').empty(); // ÆгÎ(div)ÀÇ ³»¿ë ÃʱâÈ
var table = "<table border='1'>
<tr><td>À妽º</td>
<td>¹øÈ£</td>
<td>À̸§</td>
</tr>";
// data¸¦ Ž»ö : each() ¸Þ¼µå¸¦ »ç¿ëÇؼ µ¥ÀÌÅÍ°¡ Àִ¸¸Å ¹Ýº¹
$.each(data, function (index, entry) {
table += '<tr>
';
table += '<td>' + index + '</td>
';
table += '<td>' + entry["Num"] + '</td>
';
if (entry["Name"]) { // ƯÁ¤ Çʵ带 ºñ±³ÇÒ ¶§ ÀÌ·¯ÇÑ Ç¥Çö¹ý »ç¿ë
table += '<td>' + entry["Name"] + '</td>
';
}
table += '</tr>
';
});
table += "</table>
";
$('#pnlDisplay').append(table); // Æгο¡ Ãß°¡Çϱâ
});
});
});
</script>
<div id="btn">
<div class="btnLoad">HTMLÀоî¿À±â</div>
</div>
<div id="pnlDisplay">
</div>
|
|
̵̧ : 303 |
̵̧
¸ñ·Ï
|
|