티스토리 뷰
알림창임
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Alert</title>
<link rel="stylesheet" href="main.css">
</head>
<style>
.alert-box{
background-color: skyblue;
padding: 20px;
color: white;
border-radius: 5px;
display: none;
}
</style>
<body>
<div class="alert-box" id="alert">알림창임
<button onclick="document.getElementById('alert').style.display='none';">닫기</button>
</div>
<button onclick="document.getElementById('alert').style.display='block';">버튼</button>
</body>
</html>
* 함수사용
...
<body>
<div class="alert-box" id="alert">알림창임
<button onclick="closeAlert()">닫기</button>
</div>
<button onclick="openAlert()">버튼</button>
</body>
<script>
function openAlert(){
document.getElementById('alert').style.display='block';
}
function closeAlert(){
document.getElementById('alert').style.display='none';
}
</script>
...
* 함수(parameter) 파라미터 사용 - 비슷한 함수를 하나로 작성 가능
...
<body>
<div class="alert-box" id="alert">알림창임
<button onclick="alert('none')">닫기</button>
</div>
<button onclick="alert('block')">버튼</button>
</body>
<script>
function alert(parameter){
document.getElementById('alert').style.display=parameter;
}
</script>
...
UI 만드는 step
- HTML/CSS로 미리 디자인
- 필요할 때 보여달라고 코드 짜기(JavaScript로)
- display - none(안보임) or block(보여줌) // visibility - hidden or show
함수 만들기 + 소소한 팁
- function 사용으로 간단히 한 단어로 표현하기(function 작명은 구체적으로! camelCase!)
** 코드 재사용에 용이함 - HTML 코드는 위에서부터 한 줄씩 읽어나가므로, <script>는 조작할 HTML 하단에 작성하는 것이 좋음
- 오타에 주의해야하며, 에러는 개발자 도구에서 확인하면 빠르게 확인할 수 있음
e.g. ~ of null : 찾을 수 없음.. - JavaScript에서 문자는 ''로 감싸주어야 하고, 숫자는 그냥 씀
** 참고강의
https://codingapple.com/ JavaScript 입문과 웹 UI개발
'JavaScript' 카테고리의 다른 글
[JavaScript] Bootstrap 활용하기 (0) | 2022.10.02 |
---|---|
[JavaScript] Bootstrap 시작하기 (0) | 2022.10.02 |
[JavaScript] 버튼에 따라 알림창 내용 다르게 보여주기 (0) | 2022.10.02 |
[JavaScript] 기본 (0) | 2022.10.02 |
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- 리눅스 VI
- 자바홈
- 리눅스복원
- 리눅스?
- 리눅스 종류
- GUI로 설치
- 리눅스 배우게 된 계기
- Virtual Box 설치
- 벨 연구소
- 한/영전환
- 코딩애플
- 자바는왜날힘들게할까
- 가상환경에서 리눅스설치
- 리눅스 발전과정
- CentOS 2009 vs 2207
- api키발급
- 리눅스
- 리눅스종류
- 옮긴이_안영회
- centos7
- openai
- 리눅스 배경
- 운영체제기능
- 운영체제가 하는일
- 무료크레딧
- 리눅스한영전환
- 리눅스한글안써질때
- openai_api_key
- 자바환경변수설정
- tidy_first
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
글 보관함