2024년 8월 21일
: Cascading Style Sheets
HTML을 꾸밈
<h1 style="color:rgb(173, 6, 6); text-align:center">Login</h1>
<style>
h1 {color: rgb(173, 6, 6); text-align: center}
</style>
<html>
<head>
<meta charset="UTF-8">
<title>Login</title>
<link rel="stylesheet" href="login.css">
</head>
</html>
/* login.css */
h1 {color: rgb(173, 6, 6); text-align: center}
: html요소를 선택하고 제어할 수 있는 스크립트 언어
: 프로그램을 제어하는 스크립트역할(프로그램 내부의 구성 요소 중 하나)하는 언어
*자바스크립트는 최근 빠르게 발전하고 있어서 스크립트언어만으로도 충분히 프로그래밍이 가능해져 역할이 확장되고 있음
인라인(Inline) : 사용자와의 상호작용이 있을때만 가능
ex)버튼을 클릭했을때
내부 스크립트(Internal script) : html 문서 안에 같이 작성
외부 스크립트(External script) : html 문서 밖에서 작성 및 연결
<input onclick="alert('clicked!')" id="btn_login" type="button" value="login">
<script>
/* 나만의 함수 만들고 버튼 클릭하면 호출하기 */
function myFunction() {
alert('clicked');
}
</script>
<html>
<head>
<meta charset="UTF-8">
<title>Login</title>
<script type="text/javascript" src="login.js"></script>
</head>
<body>
<input onclick="myFunction()" id="btn_login" type="button" value="login">
</body>
</html>
// login.js
function myFunction() {
alert('clicked');
}
: 특정 기능을 수행하는 코드 덩어리
ex)
function fncName() {
console.log("hello world!");
}
ex)
... 생략 ...
<body>
<form>
<input id="text_id" type="text">
<input type="password">
<input onclick="alertId()" type="button" value="login">
</form>
<script>
function alertId() {
alert(document.getElementById('text_id').value;
}
</script>
</body>
</html>
: if문
조건에 따라 결과를 다르게 할 수 있음
... 생략 ...
<body>
<form>
<input id="text_id" type="text">
<input type="password">
<input onclick="alertId()" type="button" value="login">
</form>
<script>
function alertId() {
if(!document.getElementById('text_id').value) {
alert('아이디를 입력해주세요');
} else {
alert(document.getElementById('text_id').value);
}
}
</script>
</body>
</html>
: 데이터를 담는 상자
ex)
let userId = document.getElementById("text_id").value;
if(!userId) {
alert("please write your ID");
} else {
alert(userId.value);
}
let number1 = 10;
number1 = 20;
const number3 = 30;
number3 = 40;
console.log(number1); // 20
console.log(number3); // error
함수(myFunction) 만들기
내 이름 띄우는 함수 만들기
변수를 넣어 함수 만들어 호출해보기