728x90 반응형 분류 전체보기123 window 내장객체 // window.setTimeout(함수,지연시간(ms))document.getElementById("btn1").addEventListener("click", function(){ setTimeout(function(){ alert("3초후 출력 확인!") }, 3000)})let interval; //setInterval을 저장하기 위한 전역 변수//window.setInterval(함수,지연시간(ms))function clockFn(){ const clock = document.getElementById("clock"); clock.innerHTML = currentTime(); // 현재 시간 화면에 출력 // 지연 시간 마다 반복(첫 반복도 지연시간 후에.. 2024. 6. 19. 배열 document.getElementById("btn1").addEventListener("click",function(){ //배열 선언 방법 const arr1 = new Array(3);//3칸짜리 배열 생성 const arr2 = new Array(); //0칸짜리 배열 생성 // console.log(arr1); // console.log(arr2); // 다른 자료형 대입 arr1[0]= "크로칸슈"; arr1[1]= 4500; arr1[2] = true; console.log(arr1); //0칸 배열에 대입 -> 자동으로 길이 증가 arr2[0] = "피자"; arr2[1] = 7800; arr2[2] = false;.. 2024. 6. 18. 문자열 숫자형 변환 document.getElementById("btn1").addEventListener("click",function(){ // 문자열.indexof(""); //문자열에서 "str"과 일치하는 부분이 시작되는 인덱스를 반환 //없으면 -1 반환 const str1 = "Hellow word"; console.log(str1.indexOf("e")); //1 console.log(str1.indexOf("1")); //2 가장 먼저 검색된 인덱스 반환 console.log(str1.indexOf("A")); //-1 //문자열.substring(시작인덱스, 종료인덱스) : 문자열 일부 잘라내기 // -시작 이상 종료 미만 const str2="abcd.. 2024. 6. 18. 정규표현식 DOCTYPE html>html lang="en">head> meta charset="UTF-8"> meta name="viewport" content="width=device-width, initial-scale=1.0"> title>07_정규표현식title> style> .area{ width: 500px; min-height: 300px; /*최소 300px, 내용이 높이를 초과하면 자동으로 늘어남*/ border : 1px solid black; } .confirm{color:green;} .error{color:red;} style>head>body> h1.. 2024. 6. 17. 자바스크립트 js 이벤트 //인라인 이벤트 모델 확인하기function test1(button){ // console.log(button) button.style.backgroundColor="red"; button.style.color= "white";}//고전 이벤트 모델 확인하기console.log(document.getElementById("test2-1"));document.getElementById("test2-1").onclick = function(){ //익명 함수(이벤트 핸들러에 많이 사용함) alert("고전 이벤트 모델 확인");}//이벤트 제거document.getElementById("test2-2").onclick = function(){ //test2-1 이벤트 제거 .. 2024. 6. 14. 요소 접근 방법 js// id로 접근하기function accessId(){ const div1 = document.getElementById("div1"); //접근한 요소의 배경색 얻어오기 const bgColor = div1.style.backgroundColor; // **** 자바스크립트는 문자열 비교시에도 비교 연산자를 사용!!! *** if(bgColor == "red"){ div1.style.backgroundColor="yellow"; // div1의 배경색을 yellow로 변경 }else{ div1.style.backgroundColor="red"; }}// class로 접근하기function accessClass.. 2024. 6. 13. 이전 1 ··· 12 13 14 15 16 17 18 ··· 21 다음 728x90 반응형