본문 바로가기

JavaScript&Web

[JavaScript] innerHTML 활용 예제


실제 예제



<%@ page language="java" contentType="text⁄html; charset=EUC-KR"

    pageEncoding="EUC-KR"%>
<!DOCTYPE html PUBLIC "-⁄⁄W3C⁄⁄DTD HTML 4.01 Transitional⁄⁄EN" "http:⁄⁄www.w3.org⁄TR⁄html4⁄loose.dtd">
<html>
<head>
<style type="text⁄css">
	div
	{
		margin : 10px;
		border :3px Solid Black;
		border-radius:10px;
		float:left;
		width:120px; height :120px;
		text-align:center;
	}
<⁄style>
<meta http-equiv="Content-Type" content="text⁄html; charset=EUC-KR">
<script src="http:⁄⁄code.jquery.com⁄jquery-1.7.js"><⁄script>
<script>
		var xml='<friends>';
		xml+= '		<friend>';
		xml+= '			<name>연하진<⁄name>';
		xml+= '			<language>Ruby<⁄language>';
		xml+= '		<⁄friend>';
		xml+= '	<⁄friends>';
$(document).ready(function () {
	var xmlDoc = $.parseXML(xml);
	$(xmlDoc).find('friend').each(function(index){
		var output='';
		output+='<div>';
		output+='		<h1>' + $(this).find('name').text() + '<⁄h1>';
		output+='		<p>' + $(this).find('language').text() + '<⁄p>';
		output+='<⁄div>';
		document.body.innerHTML += output;
	});
});
<⁄script>

<⁄head>
<body>

<⁄body>
<⁄html>



결과 화면