Front-end
Front-end] Javascript
김코식
2022. 11. 1. 10:56
Javascript
- 자바스크립트란 웹페이지의 동작을 넣기 위한 프로그래밍 언어
html의 <head>~</head> 안에 <script>~</script>를 사용하여 작성
예)
<script>
console.log('안녕')
</script>
작성 후 f12 클릭시 console에서 확인가능
ex) 버튼 클릭시 입력값 출력 ( 입력값이 없을 경우 문구 출력)
<!doctype html>
<html lang="ko">
<head>
<meta charset="UTF-8">
<title>연습</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<style>
.box {
width: 200px;
margin: auto;
}
</style>
<script>
function q1() {
let a = $('#input-q1').val()
if(a==''){
alert('입력된 값이 없습니다')
}
else{
alert(a)
}
}
</script>
</head>
<body>
<div class="box">
<input id="input-q1" type="text" />
<button onclick="q1()">클릭</button>
</div>
</body>
</html>
결과