일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | |||
5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 |
- 인텔리제이
- js
- input
- vscode
- 자바
- 이탈리아
- 문자열
- Eclipse
- list
- Java
- 이클립스
- json
- table
- Visual Studio Code
- 배열
- Maven
- ArrayList
- CSS
- CMD
- date
- 테이블
- Array
- html
- string
- Files
- Button
- 자바스크립트
- javascript
- IntelliJ
- windows
- Today
- Total
목록IT/Javascript (181)
어제 오늘 내일
테이블 행 개수 구하기 Header Row 1 Row 2 Row 3 Footer const table = document.getElementById('myTable'); const totalRowCnt = table.rows.length; result.innerText = '전체 행 개수: ' + totalRowCnt + '\n'; const tbody = table.tBodies[0].rows.length; result.innerText += 'Tbody 행 개수 : ' + tbody; 전체 행 개수 table.rows.length; HTMLTableElement는 rows라는 속성을 가지고, 이 속성은 모든 element를 포함하는 HTMLCollection 객체를 리턴합니다. (, , 안의 모든 을..
class 이름 읽기 class 추가/수정 class 삭제 class toggle 특정 클래스 이름이 class 속성에 포함되는지 확인하기 1. class 이름 읽기 예제 1. className function handleOnClick() { alert(document.getElementById('ex').className); } document.getElementById('ex').className; element.className 속성은 element의 클래스 이름을 문자열로 리턴합니다. 예제 2. classList // class 이름 읽기 function getClassName() { alert(document.getElementById('ex').classList); } // class item..
지난번에는 Javascript에서 사용할 수 있는 알림창의 종류에 대해서 알아보았습니다. [Javascript] 알림창 종류 (alert, confirm, prompt) 모든 알림창에는 메시지를 표시할 수 있는데, 이 메시지를 줄바꿈하여 여러줄 표시할 수 있는 방법을 알아보도록 하겠습니다. function handleOnClick() { alert('a\nb\nc'); alert(`d e f`); } '\n'을 이용하는 방법 alert('a\nb\nc'); 줄바꿈을 하고 싶은 곳에 '\n'을 입력합니다. 템플릿 문자열을 이용하는 방법 alert(`a b c`); 백틱(`)으로 감싸인 문자열인 템플릿 문자열을 이용하면 백틱 사이의 내용이 그대로 문자열로 전환됩니다. 줄바꿈 표시도 따로 '\n'을 쓸 필요없..
Javascript에서 사용할 수 있는 메시지 박스 3종류 alert confirm prompt 1. alert function handleOnClick() { alert('Hello!!'); } alert()은 사용자가 확인 버튼을 누를때까지 메세지를 보여주는 창입니다. 2. confirm function handleOnClick() { let like = confirm("좋아요 눌러주실거죠?"); document.getElementById('result').innerText = like; } confirm()은 사용자에게 메세지를 보여주고, [확인/취소] 중 둘 중 하나를 선택하도록 합니다. confirm()은 사용자가 [확인]을 선택하면 true를 리턴하고, [취소]를 선택하면 false를 리턴합니..
2개 이상의 객체를 합쳐서 하나의 객체로 만드는 방법 4가지를 소개합니다. 반복문 사용하기 Object.assign() Spread Operator (전개연산자) _.merge() (lodash 라이브러리) 1. 반복문 사용하기 const obj1 = { name : 'banana', price : 1000 }; const obj2 = { name : 'banana', price : 2000, count : 10 }; // merge object 함수 function mergeObj(obj1, obj2) { const newObj = {}; for (let att in obj1) { newObj[att] = obj1[att]; } for(let att in obj2) { newObj[att] = obj2..
Javascript에서 URL에 포함된 파라미터(쿼리스트링)의 값을 읽어오는 방법입니다. 현재 페이지의 URL과 파라미터 읽기 특정 파라미터 값 읽기 특정 파라미터가 있는지 체크하기 파라미터 추가, 변경, 삭제하기 전체 파라미터 목록 가져오기 1. 현재 페이지의 URL과 파라미터 읽기 현재 페이지의 URL을 가져오는 방법과 쿼리스트링을 가져오는 방법은 지난 포스팅에서 소개했습니다. [Javascript] 현재 페이지 URL 가져오기 간단하게 다시 정리하면 현재 페이지의 URL을 가져오기 위해서는 아래와 같이 하고, // "https://hianna.tistory.com/325?category=764998" window.location.href 전체 URL중 쿼리스트링(파라미터)만 가져오고 싶은 경우에는 ..
Javascript에서 현재 페이지의 URL 주소를 가져오는 방법을 소개합니다. window.location (Location 객체) 현재 페이지의 URL을 알아오기 위해 window.location 속성을 사용할 수 있습니다. window.location 속성에 접근하면 Location 객체에 접근할 수 있는데 이 Location 객체의 속성들을 사용해서 현재 페이지의 URL 정보를 알아낼 수 있습니다. // "https://hianna.tistory.com/325?category=764998" window.location.href // "https:" window.location.protocol // "hianna.tistory.com" window.location.host // "hianna.tis..
Javascript에서 값이 정수인지 실수인지 체크하는 2가지 방법을 소개합니다. Number.isInteger() 함수 나머지 연산자(%) 활용 1. Number.isInteger() 함수 document.writeln(Number.isInteger(10)); // true document.writeln(Number.isInteger(0)); // true document.writeln(Number.isInteger(-10)); // true document.writeln(Number.isInteger(123.1)); // false Number.inInteger() 함수는 파라미터로 입력받은 값이 정수인지 판단합니다. 가장 간단하게, 데이터가 정수인지 판단할 수 있는 방법입니다. 하지만, 이 함수는 ..
Javascript에서 빈 객체를 체크하는 방법입니다. Object.keys() 함수 반복문 사용하기 lodash library 사용하기 1. Object.keys() 함수 function isEmptyObj(obj) { if(obj.constructor === Object && Object.keys(obj).length === 0) { return true; } return false; } const obj1 = {}; const obj2 = {name: 'js'}; const str = "Javascript"; document.writeln(isEmptyObj(obj1)); // true document.writeln(isEmptyObj(obj2)); // false document.writeln(i..
Javascript에서 특정 객체가 배열인지, 그리고 그것이 배열이라면 빈 배열인지 확인하는 방법입니다. 빈 배열 체크하기 const arr1 = []; const arr2 = [1, 2]; const obj = {}; const str = ""; function isEmptyArr(arr) { if(Array.isArray(arr) && arr.length === 0) { return true; } return false; } document.writeln(isEmptyArr(arr1)); // true document.writeln(isEmptyArr(arr2)); // false document.writeln(isEmptyArr(obj)); // false document.writeln(isEmpt..