Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 | 28 | 29 | 30 | 31 |
Tags
- thread
- array
- 파이썬
- 스프링부트
- 객체
- event
- SpringBoot
- SSL
- 메소드
- Docker Desktop
- JS
- c#
- 자바
- 저장소
- JavaScript
- 프로그래머스스쿨
- Java
- Python
- class
- Dict
- 클래스
- 자바스크립트
- GIT
- docker
- Swing
- synchronized
- 배열
- StringBuilder
- join()
- AssertJ
Archives
- Today
- Total
정리노트
[JAVASCRIPT/자바스크립트] 메소드(onclick/text/html/attr/appendTo) 본문
<!DOCTYPE html>
<html>
<head>
<title>Event Basic</title>
<button id = "bt">버튼을 누르세요.</button>
<script>
window.onload = function () {
const rbt = document.getElementById("bt");
rbt.onclick = function () {
//load >> 이벤트 이름, 이벤트 타입 / 그 안의 속성 <function> 부터는 이벤트 핸들러, 이벤트 리스너
this.innerHTML = this.innerHTML + "★"
// this : current element (현재 선택된 요소)
};
}
</script>
</head>
<body>
<button id = "bt"버튼을 누르세요.></button>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<title>jQuery Text</title>
<script src="jquery-3.6.0.min.js"></script>
<script>
$(document).ready(function () {
// text() 메소드와 html() 메소드의 리턴 값을 출력합니다.
alert($('p').text()); // 전체 p 태그에서 전체 문서객체
alert($('p').html()); // 전체 p 태그에서 첫 번째 문서객체
});
</script>
</head>
<body>
<p>TestA</p>
<p>TestB</p>
<p>TestC</p>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<title>jQuery Text</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.1/jquery.min.js"></script>
<script>
$(document).ready(function () {
$('.text-1').text('<h1>text() 메소드</h1>'); // .text() 내부에 태그가 있다면 태그도 문자로 인식
$('.text-2').html('<h1>html() 메소드</h1>'); // .html() 내부에 태그가 있다면 태그를 적용
});
</script>
</head>
<body>
<p class="text-1">TestA</p>
<p class="text-1">TestA</p>
<p class="text-2">TestB</p>
<p class="text-2">TestB</p>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<title>jQuery Attribute</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.1/jquery.min.js"></script>
<script>
// 웹 페이지를 모두 불러오면
$(document).ready(function () {
// img 태그에
$('img').each(function (index, element) {
// src 속성을 조작합니다.
$(this).attr('src', 'https://via.placeholder.com/' + (index + 1) * 100 + 'x100');
// attr() 메소드 -> img 태그 별 속성을 변경함. (반복으로 각 태그 속성값 변경)
});
});
</script>
</head>
<body>
<img />
<img />
<img />
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<title>jQuery Event</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.1/jquery.min.js"></script>
<script>
// 웹 페이지를 모두 불러오면
$(document).ready(function () {
// 0부터 255까지 반복문을 돌리고
for (var i = 0; i < 256; i++) {
// div 태그에 스타일을 적용해 body 태그에 추가합니다.
$('<div></div>').css({
height: 2,
background: 'rgb(' + (255-i) + ',' + (103 - i) + ',' + i + ')'
}).appendTo('body'); // body 태그에 추가
}
});
</script>
</head>
<body>
</body>
</html>
728x90
'프로그래밍 > Javascript' 카테고리의 다른 글
[JAVASCRIPT/자바스크립트] 선택자 / 활용 (0) | 2022.12.06 |
---|---|
[JAVASCRIPT/자바스크립트] Loop (0) | 2022.12.06 |
[JAVASCRIPT/자바스크립트] 자바스크립트 HTML 실행순서 / 이벤트 활용 (0) | 2022.12.06 |
[JAVASCRIPT/자바스크립트] lodash 라이브러리 sortBy (0) | 2022.11.19 |
[JAVASCRIPT/자바스크립트] 객체 내부 배열정렬 (0) | 2022.11.19 |