๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
front-end

[bootstrap] ๋ถ€ํŠธ์ŠคํŠธ๋žฉ ์‚ฌ์šฉ๋ฒ•

by CodeMango 2023. 2. 22.

๐ŸŽˆ๋ถ€ํŠธ์ŠคํŠธ๋žฉ์€ ์ฝ”๋“œ๋Š” ๊ตฌ๊ธ€๋งํ•˜๊ฑฐ๋‚˜ ๋„์›€๋˜๋Š” ์‚ฌ์ดํŠธ์—์„œ ์ฐธ์กฐํ•ด์„œ ์ž˜ ๋ฐฐ์น˜ํ•ด์ฃผ๋Š” ๊ฒƒ์ด ์ค‘์š”ํ•ฉ๋‹ˆ๋‹ค.

 

๊ตฌ๊ธ€๋ง

loginํ™”๋ฉด ๊ตฌํ˜„์‹œ bootstrap login ์ด๋ผ๊ณ  ๊ฒ€์ƒ‰

checkboxํ™”๋ฉด ๊ตฌํ˜„์‹œ bootstrap checkbox๋ผ๊ณ  ๊ฒ€์ƒ‰

 

์ฐธ์กฐ ์‚ฌ์ดํŠธ

1. https://mdbootstrap.com/docs/standard/extended/login/

 

Bootstrap Login Form - free examples, templates & tutorial

Responsive login form built with Bootstrap 5. Collection of examples for signup forms, full page login templates, login modals & many other sign in designs.

mdbootstrap.com

2. https://www.w3schools.com/bootstrap4/bootstrap_buttons.asp

 

Bootstrap 4 Buttons

W3Schools offers free online tutorials, references and exercises in all the major languages of the web. Covering popular subjects like HTML, CSS, JavaScript, Python, SQL, Java, and many, many more.

www.w3schools.com

 

 

๐ŸŽˆw3school ๋ถ€ํŠธ์ŠคํŠธ๋žฉ ์‚ฌ์šฉํ•˜๋Š” ๋ฐฉ๋ฒ•

 

1. <title>๋ถ€๋ถ„์— ์•„๋ž˜ ์ฝ”๋“œ๋ฅผ ์ถ”๊ฐ€ํ•ด์„œ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.

  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.6.2/dist/css/bootstrap.min.css">
  <script src="https://cdn.jsdelivr.net/npm/jquery@3.6.3/dist/jquery.slim.min.js"></script>
  <script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.1/dist/umd/popper.min.js"></script>
  <script src="https://cdn.jsdelivr.net/npm/bootstrap@4.6.2/dist/js/bootstrap.bundle.min.js"></script>

 

2. ์‚ฌ์ดํŠธ์—์„œ ๋ณต์‚ฌํ•ด์˜จ ์ฝ”๋“œ๋ฅผ ๋ณต์‚ฌ-๋ถ™์—ฌ๋„ฃ๊ธฐ ํ•˜์—ฌ ๋ฐฐ์น˜ํ•ฉ๋‹ˆ๋‹ค.

 

3. ๊ธฐ์กด์˜ ์ฝ”๋“œ์™€ id์™€ type ๋“ฑ์„ ๋งž์ถฅ๋‹ˆ๋‹ค.

 

<์‹ค์ œ์˜ˆ์ œ>

    <%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.1/jquery.min.js"></script>

<!-- ๋ถ€ํŠธ์ŠคํŠธ๋žฉ ์ถ”๊ฐ€ํ•˜๊ธฐ ์œ„ํ•ด w3school์—์„œ ๊ฐ€์ ธ์˜จ ๋งํฌ 
์–ด๋–ค ์ฝ”๋“œ๊ฐ€ ์–ด๋–ค ์—ญํ• ์„ ํ•˜๋Š”์ง€ ๋นผ๋ณด๋ฉด์„œ ์•Œ์•„๋ณด๊ธฐ -->
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.6.2/dist/css/bootstrap.min.css">
  <script src="https://cdn.jsdelivr.net/npm/jquery@3.6.3/dist/jquery.slim.min.js"></script>
  <script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.1/dist/umd/popper.min.js"></script>
  <script src="https://cdn.jsdelivr.net/npm/bootstrap@4.6.2/dist/js/bootstrap.bundle.min.js"></script>
  
<script src="http://lab.alexcican.com/set_cookies/cookie.js" type="text/javascript" ></script>
	<-- ์œ„ ์ฝ”๋“œ๊ฐ€ ์ด ์ž๋ฆฌ์— ์žˆ์–ด์•ผ ์ฟ ํ‚ค๊ฐ€ ์ œ๋Œ€๋กœ ์ž‘๋™ํ•œ๋‹ค-->

<style type="text/css">
.divider:after,
.divider:before {
  content: "";
  flex: 1;
  height: 1px;
  background: #eee;
}
.h-custom {
  height: calc(100% - 73px);
}
@media (max-width: 450px) {
  .h-custom {
    height: 100%;
  }
}
</style>

</head>
<body>
<!-- ๋ถ€ํŠธ์ŠคํŠธ๋žฉ ์ฝ”๋”ฉ ์‹œ์ž‘ -> ๊ธฐ์กด์˜ ํ…œํ”Œ๋ฆฟ ๋ถ™์—ฌ๋„ฃ๊ธฐ ํ•จ -->
<section class="vh-100">
  <div class="container-fluid h-custom">
    <div class="row d-flex justify-content-center align-items-center h-100">
    
		<div class="col-md-9 col-lg-6 col-xl-5">
        <img src="https://www.multicampus.com/kr/images/main/2021/tab-image3.jpg" class="img-fluid"
          alt="Sample image">
     	 </div>
      
      <div class="col-md-8 col-lg-6 col-xl-4 offset-xl-1">
      <form action="loginAf.do" method="post">
      	<div class="d-flex flex-row align-items-center justify-content-center justify-content-lg-start">
            <p class="lead fw-normal mb-0 me-3">Sign in with</p>            
          </div>

          <div class="divider d-flex align-items-center my-4">
            <p class="text-center fw-bold mx-3 mb-0">Or</p>
          </div>
          
          <!-- id input -->
          <div class="form-outline mb-4">
            <input type="text" id="id" name="id" class="form-control form-control-lg"
              placeholder="Enter a valid id" />
            <label class="form-label" for="form3Example3">Id</label>
          </div>
          
          <!-- Password input -->
          <div class="form-outline mb-3">
            <input type="password" id="form3Example4" name="pwd" class="form-control form-control-lg"
              placeholder="Enter password" />
            <label class="form-label" for="form3Example4">Password</label>
          </div>
      
      	  <!--  ์•„์ด๋””์ €์žฅ ์ฒดํฌ๋ฐ•์Šค ๋งŒ๋“ค๊ธฐ -->
      	  <div class="d-flex justify-content-between align-items-center">
            <!-- Checkbox -->
            <div class="form-check mb-0">
              <input class="form-check-input me-2" type="checkbox" value="" id="chk_save_id" />
              <label class="form-check-label" for="form2Example3">
                Remember me
              </label>
            </div>
            <a href="#!" class="text-body">Forgot password?</a>
          </div>
          
          <!-- login๋ฒ„ํŠผ ๋งŒ๋“ค๊ธฐ -->
          <div class="text-center text-lg-start mt-4 pt-2">
            <button type="submit" class="btn btn-primary btn-lg"
              style="padding-left: 2.5rem; padding-right: 2.5rem;">Login</button>
            <p class="small fw-bold mt-2 pt-1 mb-0">Don't have an account? 
            	<a href="#" onclick="account()" class="link-danger">Register</a></p>
          </div>
      
      </form>  
</div>
</div>
</div>
	<!--  ์•„๋ž˜์— ํŒŒ๋ž€์ค„ ๋งŒ๋“ค๊ธฐ -->
	<div class="d-flex flex-column flex-md-row text-center text-md-start justify-content-between py-4 px-4 px-xl-5 bg-primary">
    <!-- Copyright -->
    <div class="text-white mb-3 mb-md-0">
      Copyright ©๏ธ 2021. MultiCampus.
    </div>
    <!-- Copyright -->

    <!-- Right -->
    <div>
      <a href="#!" class="text-white me-4">
        <i class="fab fa-facebook-f"></i>
      </a>
      <a href="#!" class="text-white me-4">
        <i class="fab fa-twitter"></i>
      </a>
      <a href="#!" class="text-white me-4">
        <i class="fab fa-google"></i>
      </a>
      <a href="#!" class="text-white">
        <i class="fab fa-linkedin-in"></i>
      </a>
    </div>
    <!-- Right -->
  </div>
</section>


<script type="text/javascript">
//ํšŒ์›๊ฐ€์ž… ๋ฉ”์„œ๋“œ
function account(){
	location.href = "regi.do";
	
}

let user_id = $.cookie("user_id");

if(user_id != null){	// ์ €์žฅํ•œ id๊ฐ€ ์žˆ์Œ
	$("#id").val(user_id);
	$("#chk_save_id").prop("checked", true);
}

$("#chk_save_id").click(function () {
	
	if( $("#chk_save_id").is(":checked") == true ){
		
		if( $("#id").val().trim() == "" ){
			alert('id๋ฅผ ์ž…๋ ฅํ•ด ์ฃผ์‹ญ์‹œ์˜ค');
			$("#chk_save_id").prop("checked", false);
		}else{
			// cookie๋ฅผ ์ €์žฅ
			$.cookie("user_id", $("#id").val().trim(), { expires:7, path:'./' });
		}
		
	}else{
		$.removeCookie("user_id", { path:'./' });
	}	
});

</script>

</body>
</html>

๋Œ“๊ธ€