s23_appendTo.html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>문서객체 생성</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.7.1/jquery.min.js">
</script>
<script type="text/javascript">
/*
메서드 이름 설명
$(A).appendTo(B) A를 B의 기존 자식의 뒤에 추가
$(A).prependTo(B) A를 B의 기존 자식의 앞에 추가
$(A).insertAfter(B) A를 B의 뒤에 형제로 추가
$(A).insertBefore(B) A를 B의 앞에 형제로 추가
*/
$(function(){
//문서 객체 생성
//$('<h1>Hello World</h1>').appendTo('div');
//$('<h1>Hello World</h1>').prependTo('div');
//$('<h1>Hello World</h1>').insertAfter('div');
$('<h1>Hello World</h1>').insertBefore('div');
});
</script>
</head>
<body>
<div>
<h1>안녕하세요</h1>
</div>
</body>
</html>
s24_appendTo.html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>문서객체 생성</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.7.1/jquery.min.js">
</script>
<script type="text/javascript">
$(function(){
//태그 생성
$('<img>').attr({//새로생성한 태그
src:'../files/Koala.jpg',
width:400,
height:250
}).appendTo('body');//기존태그
});
</script>
</head>
<body>
</body>
</html>
s25_appendTo.html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>문서 객체 생성</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.7.1/jquery.min.js">
</script>
<script type="text/javascript">
$(function(){
$('img').css('width',250);
//2초마다 매개변수로 전달되는 함수를 실행
setInterval(function(){
//첫 번째 이미지를 마지막으로 보냄
$('img').first().appendTo('body');
},2000);
});
</script>
</head>
<body>
<img src="../files/Chrysanthemum.jpg">
<img src="../files/Desert.jpg">
<img src="../files/Hydrangeas.jpg">
<img src="../files/Jellyfish.jpg">
<img src="../files/Koala.jpg">
</body>
</html>
s26_appendTo.html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>문서 객체 생성 및 추가</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.7.1/jquery.min.js">
</script>
<script type="text/javascript">
/*
메서드 이름 설명
$(A).append(B) B를 A의 기존 자식의 뒤에 추가
$(A).prepend(B) B를 A의 기존 자식의 앞에 추가
$(A).after(B) B를 A의 뒤에 형제로 추가
$(A).before(B) B를 A의 앞에 형제로 추가
*/
$(function(){
//$('div').append('<h1>Hello jQuery</h1>');
//$('div').prepend('<h1>Hello jQuery</h1>');
//$('div').after('<h1>Hello jQuery</h1>');
$('div').before('<h1>Hello jQuery</h1>');
});
</script>
</head>
<body>
<div>
<h1>여기는 겨울</h1>
</div>
</body>
</html>
s27_appendTo.html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>문서 객체 생성 및 추가</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.7.1/jquery.min.js">
</script>
<script type="text/javascript">
$(function(){
//배열 생성
const content = [
{name:'김유신',region:'경주'},
{name:'이순신',region:'여수'},
{name:'홍길동',region:'서울'}
];
let output ='';
// 배열 , 배열의 요소에 접근할 때 호출되는 메서드
$.each(content,function(index,item){
//index : 배열의 index
//item : 배열의 요소(객체)
output += '<div>';
output += '<h2>'+item.name +'</h2>';
output += '<span>' +item.region+'</span>';
output +='</div>';
});
// 기존태그 새로만든태그
$('#output').append(output);
});
</script>
<body>
<div id="output"></div>
</body>
</html>
s28_appendTo.html(실습)
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>실습</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.7.1/jquery.min.js">
</script>
<script type="text/javascript">
$(function(){
/*
[실습]
도서 정보를 table에 표시하시오. 배열에 도서명,분류,정상가격 저장. 할인가격은 연산에 의해서 만들기
--------------------------
도서명 분류 정상가격 할인가격(5%)
자바 It 20,000 19,000원
미술사 예술 30,000 28,500원
노래연습 예술 10,000 9,500원
한국사 역사 50,000 47,000원
*/
//배열 생성
const book = [
{name:'자바',category:'It',price:20000},
{name:'미술사',category:'예술',price:30000},
{name:'노래연습',category:'예술',price:10000},
{name:'한국사',category:'역사',price:50000}
];
let output =' <tr><th>도서명</th><th>분류</th><th>정상가격</th><th>할인가격(5%)</th></tr>';
// 배열 , 배열의 요소에 접근할 때 호출되는 메서드
$.each(book,function(index,item){
//index : 배열의 index
//item : 배열의 요소(객체)
output += '<tr>';
output += '<td>'+item.name +'</td>';
output += '<td>' +item.category+'</td>';
output += '<td>' +item.price.toLocaleString()+'원</td>';
output += '<td>' +(item.price*0.95).toLocaleString()+'원</td>';
output +='</tr>';
});
// 기존태그 새로만든태그
$('#output').append(output);
});
</script>
</head>
<body>
<table id="output" border="1"></table>
</body>
</html>
'쌍용교육(JAVA) > jquery' 카테고리의 다른 글
쌍용교육 -jquery수업 42일차 jQuertEvent(2) (0) | 2024.04.17 |
---|---|
쌍용교육 -jquery수업 41일차 jQuertEvent(1) (0) | 2024.04.16 |
쌍용교육 -jquery수업 41일차 jQuerySelector(2) (0) | 2024.04.16 |
쌍용교육 -jquery수업 41일차 jQuerySelector(1) (0) | 2024.04.16 |
쌍용교육 -jquery수업 40일차 다운로드,jQuerySelector (0) | 2024.04.15 |