Javascript [ 페이지 이동, KeyCode, URI ]

양혜정·2024년 4월 13일
0

javascript_web

목록 보기
31/81

페이지 이동

location.href = "위치"

<button type="button" onclick="location.href
	= '다른 html 파일'">버튼속안의말</button>

confirm

  • 알림창이 아닌 선택할 수 있는 기능
  • 확인 버튼 클릭 시 true, 취소 버튼 클릭 시 false 가 된다.

이벤트 설정 ( Keycode )

클릭하여 검색하는 경우도 있지만 엔터를 통해 검색하는 경우도 있기 때문에 두가지 모두 설정하기

document.querySelector("버튼위치").onclick = () => {
  ...
}
document.querySelector("입력위치").onkeydown = (e) => {
	if(e.keyCode == 13){	// 엔터를 입력하면
      	...
    }
}

KeyCode

  • 키보드 및 운영체제의 차이가 존재하고, 국가별 레이아웃이 다른 등 여러 이유때문에 keycode는 다를 수 있다.

  • Windows => PrintScreen 일반적으로 44

  • macOS => Command + Shift + 3
    Command : 91, Shift : 16, 3 : 51


URI

  • 한글을 txt 파일로 가져오면 깨져서 나온다.
  • encode 와 decode 를 이용

EncodeURI

  • encodeURI("문자열")
    "문자열"을 컴퓨터가 알아듣는 문자로 변환

DecodeURI

  • decodeURI(값)
    컴퓨터가 알아듣는 문자를 사람이 알아볼 수 있도록 변환
const encodeVal = encodeURI(inputText);	// 컴퓨터 언어
// inputText 는 입력한 값에 대한 변수명
const decodeVal = decodeURI(encodeVal);	// 사람 언어

정리

  • 09_javascriptStandardObject -> 03URI
    -> encodeURI_decodeURI.html,encodeURI_decodeURI.css, encodeURI_decodeURI.js
  • quiz_exam_slide_teacher
    -> start.html, quiz_exam_slide.js

0개의 댓글

관련 채용 정보