• 카테고리

    질문 & 답변
  • 세부 분야

    프로그래밍 언어

  • 해결 여부

    해결됨

제발 도와주세요

23.07.11 11:38 작성 23.07.11 11:41 수정 조회수 577

-4

javascript로 프로젝트 하는 학생입니다.

제가 지금 로그인 창으로 적은 아이디,비번,이메일을 적은 값을 저장해

다른 html창으로 보내는 것을 하고 싶은 데 잘 안되고 있습니다.

(방문자 로그를 만들기 위해)

도움이 필요 합니다..

<방문자 로그를 표시할 창>->ex) jjj.html

<로그인 창 코드>

<html>

<div style="text-align: center;">

<img src="file:///C:/Users/User/Pictures/image%20(2).png" height="300" width="300">

</div>

<title>mago market</title>

<body> <style>p{text-align: center;}</style>

</body>

<script> const input = document.querySelector("input"); let text = input.innertext; localstorage.setItem("text", text); </script>

<form action="file:///C:/Users/User/jjj.html" method="post" class="input form"> <p style="color:rgb(202, 202, 202) ">아이디는 첫 글자를 영어를 포함해 주세요</p>

<p>아이디: <input type="text" id="id" required pattern="[a-zA-Z].+" placeholder="아이디를 작성해 주세요" class="input id"></p>

<p>비밀번호: <input type="password" id="pwd" required placeholder="비밀번호를 작성해 주세요" class="input pw"></p>

<p>이메일: <input type="email" id="email" placeholder="이메일을 작성해 주세요" required></p>

<p>gps 및 위치 정보를 공유하는 것을 동의합니까? <input type="checkbox" name="agree" required></p>

<p>계정 정보를 수집하는 것을 동의합니까? <input type="checkbox" name="yes" required></p>

<div style="text-align: center;"> <input type="submit" type="button" value="로그인"> </div> <script type="text/javascript">

alert("이곳은 GSM 학생들이 사용할 Mago Market 사이트 페이지 입니다.\n참고하시길 바랍니다.\n제작자 진건희"); </script>

</form>

답변 1

답변을 작성해보세요.

0

인프런 AI 인턴님의 프로필

인프런 AI 인턴

2023.07.13

안녕하세요, 인프런 AI 인턴이에요. 지금 문제가 되고 있는 부분은 로그인 창에서 입력한 값을 다른 HTML 창으로 보내는 것이죠?
먼저 로그인 창에서 입력한 값을 저장해야 합니다. 그리고 다른 HTML 창으로 보내는 방법은 다양한 방법이 있습니다. 그 중 하나는 form을 사용하여 POST 방식으로 데이터를 보내는 것입니다.
먼저 로그인 창에서 입력한 값을 저장하는 코드는 다음과 같이 작성할 수 있습니다.

const idInput = document.getElementById("id");
const pwdInput = document.getElementById("pwd");
const emailInput = document.getElementById("email");

const loginForm = document.querySelector(".input.form");

loginForm.addEventListener("submit", function (e) {
  e.preventDefault();

  const id = idInput.value;
  const pwd = pwdInput.value;
  const email = emailInput.value;

  localStorage.setItem("id", id);
  localStorage.setItem("pwd", pwd);
  localStorage.setItem("email", email);

  // 다른 HTML 창으로 이동하는 코드 작성
});

위의 코드에서는 submit 이벤트가 발생했을 때, 입력한 값들을 localStorage에 저장하고 다른 HTML 창으로 이동하는 코드가 작성되어야 합니다. 다른 HTML 창으로 이동하는 부분은 원하시는 방식에 따라 다르게 작성하실 수 있습니다.

그리고 다른 HTML 창에서 localStorage에 저장된 값을 가져오는 방법은 다음과 같이 작성할 수 있습니다.

const id = localStorage.getItem("id");
const pwd = localStorage.getItem("pwd");
const email = localStorage.getItem("email");

// 가져온 값들을 사용하여 작업을 수행

하지만, 주의해야 할 점은 localStorage에 저장된 값은 브라우저 종료 후에도 유지되므로, 보안에 민감한 정보를 저장하기에는 적합하지 않습니다. 이를 주의하시고 사용하시기 바랍니다.

어떤 점이 더 도움이 필요하신지 더 자세히 알려주시면 더 도움을 드릴 수 있을 것 같아요.