생각보다 까다롭고 어려웠다 ㅜ 이전에 배운 html, css는 양반 ㅜㅜ
(그치만 매번 쉬운 것만 연습하면 의미가 없으니 분발하자!! ㅎㅎㅎ)

Q1. 버튼을 눌렀을 때 칸에 아무것도 없으면 '입력하세요'라는 얼럿 띄우기
Q2. 버튼을 눌렀을 때 입력받은 이메일로 얼럿 띄우기(이메일이 아니면 아니라고 얼럿)+이메일의 도메인만 추출해서 얼럿
<Q3> - html 붙이기/지우기 연습
Q3-1. 이름을 입력하면 아래 나오게 하기
Q3-2. 다지우기 버튼을 만들기
<!doctype html>
<html lang="ko">
<head>
<meta charset="UTF-8">
<title>jQuery 연습하고 가기!</title>
<!-- JQuery를 import 합니다 -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<style type="text/css">
div.question-box {
margin: 10px 0 20px 0;
}
</style>
<script>
function q1(){
let tt = $('#input-q1').val()
if (tt ==''){
alert('입력해주세요')
} else {
alert(tt)
}
}
function q2(){
let txt = $('#input-q2').val()
if (txt.includes('@')==true){
alert
(txt.split('@')[1].split('.')[0])
}else{
alert(
'올바른 형식이 아닙니다'
)
}
}
function q3(){
let txtx=$('#input-q3').val()
if (txtx==''){
alert('이름을 입력하세요')
}
let temp_html = `<li>${txtx}</li>`
$('#names-q3').append(temp_html)
}
function q3_remove(){
$('#names-q3').empty()
}
</script>
</head>
<body>
<h1>jQuery + Javascript의 조합을 연습하자!</h1>
<div class="question-box">
<h2>1. 빈칸 체크 함수 만들기</h2>
<h5>1-1. 버튼을 눌렀을 때 입력한 글자로 얼럿 띄우기</h5>
<h5>[완성본]1-2. 버튼을 눌렀을 때 칸에 아무것도 없으면 "입력하세요!" 얼럿 띄우기</h5>
<input id="input-q1" type="text" /> <button onclick="q1()">클릭</button>
</div>
<hr />
<div class="question-box">
<h2>2. 이메일 판별 함수 만들기</h2>
<h5>2-1. 버튼을 눌렀을 때 입력받은 이메일로 얼럿 띄우기</h5>
<h5>2-2. 이메일이 아니면(@가 없으면) '이메일이 아닙니다'라는 얼럿 띄우기</h5>
<h5>[완성본]2-3. 이메일 도메인만 얼럿 띄우기</h5>
<input id="input-q2" type="text" /> <button onclick="q2()">클릭</button>
</div>
<hr />
<div class="question-box">
<h2>3. HTML 붙이기/지우기 연습</h2>
<h5>3-1. 이름을 입력하면 아래 나오게 하기</h5>
<h5>[완성본]3-2. 다지우기 버튼을 만들기</h5>
<input id="input-q3" type="text" placeholder="여기에 이름을 입력" />
<button onclick="q3()">이름 붙이기</button>
<button onclick="q3_remove()">다지우기</button>
<ul id="names-q3">
<li>세종대왕</li>
<li>임꺽정</li>
</ul>
</div>
</body>
</html>
'코딩' 카테고리의 다른 글
+) 그라데이션 넣기! (0) | 2022.06.29 |
---|---|
프로필 링크 페이지 제작(자체 휴식 ㅎㅎㅎ) (0) | 2022.06.29 |
코딩교육 2주차(포스팅박스 열기 닫기 감추기 ) (0) | 2022.06.26 |
코딩교육 2주차(이름도 생소한... JQuery) (0) | 2022.06.26 |
코딩의 기초!!! (0) | 2022.06.23 |