웹 개발 공부중
버튼(Flip-Flop) 함수 javaScript
redeyes
2021. 12. 14. 10:42
버튼 클릭을 토글방식처럼 on/off가능함 응용하면 더욱 다양하게 적용할 수 있음
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<script>
var count=1;
function hey(){
alert('버튼');
count += 1;
if(count % 2 == 0)
alert('ON')
else
alert('OFF')
}
</script>
</head>
<body>
<button onclick="hey();">버튼</button>
</body>
</html>
여기에 부트스트랩 적용하면
아래처럼 더 길게 쓸수 있어요. 🤦♂️
<!doctype html>
<html lang="ko">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/js/bootstrap.bundle.min.js"
integrity="sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM"
crossorigin="anonymous"></script>
<style>
button {
margin: 100px;
}
</style>
<script>
var count=1;
function hey(){
alert('안녕');
count += 1;
if(count % 2 == 0)
alert('ON')
else
alert('OFF')
}
</script>
<title>부트스트랩 연습하기</title>
</head>
<body>
<button type="button" class="btn btn-dark">버튼</button>
</body>
</html>