728x90 300x250 SMALL javaScript545 forEach 반복문으로 배열값 전체 호출하기 forEach는 반복문 중에서 오직 배열 Array 객체에서만 사용 가능한 메서드이다. (ES6부터 Map, Set 지원) map과 비슷해 보이지만 forEach는 return값이 없다. forEach 구문의 인자로 콜백함수를 등록해서 배열 첫 번째부터 마지막 번까지 반복해서 item을 호출하게 된다. 예제를 보도록 하자 let text = ""; const number = [1,2,3,4,5]; number.forEach(numArray); function numArray(item, index) { console.log(index + '.' + item); } 결과 numArray의 인자로 현재 item과 index값을 넘겨받아 출력한다. 만약 이 값을 차례로 html 태그 안에 나타내려면? inner.. 2022. 4. 24. javaScript 브라우저 IE(익스플로러) 체크 + IE11 포함 ie(익스플로러) 버전 체크는 아래처럼 MSIE 문자열을 이용하면 된다. navigator.userAgent.indexOf("MSIE") > 0 if(/MSIE/.test(navigator.userAgent)) { if(navigator.userAgent.indexOf("MSIE") > 0) { console.log('ie'); } else { console.log('ie10'); } } else { console.log('etc'); } ie10 이하 버전은 콘솔 창에 ie가 ie10 버전은 ie10이 표출된다. 그리고 etc는 ie 이외의 다른 브라우저들이 나타나야 하지만 ie11도 else로 걸러지게 된다. 그 이유는 MS가 IE11부터 웹표준에 맞추기 위해 User Agent String의 리턴 .. 2022. 4. 22. jQuery 이미지 가로 정렬 구하기 jQuery를 이용해서 이미지 가로 정렬 구하는 방법 html css #img-list img {position:absolute; width: 100px;height: 100px;padding: 10px;} css positon:absoute로 변경해 줘야 한다. jQuery let $imgList = null; //이미지를 담을 imgList제이쿼리 변수 선언 $(document).ready(function() { $imgList = $("#img-list img"); //이미지를 찾아서 $imgList에 넣는다. console.log ($imgList.length); for(let i=0 ; i < $imgList.length ;i++) { // 이미지 개수만큼 반복 let $img = $imgLis.. 2022. 4. 20. jQuery 제이쿼리 cdn 최신버전 사용하기 아래와 같이 cdn을 등록하면 항상 최신 버전의 제이쿼리를 사용할 수 있다. 2022. 4. 18. 이전 1 ··· 97 98 99 100 101 102 103 ··· 137 다음 728x90 반응형 LIST