본문 바로가기

반응형

JavaScript

javascript 에서 replace 를 문자열 전체에 적용하기 자바스크립트 REPLACE 를 사용해서 문자열 치환을 하면 첫번째 하나만 치환이 된다. 문자열 전체에 적용하고자 하면 정규식을 사용하여 치환해야 한다. ex) ' (작은따옴표) 를 없애고자 한다면 var str = "aaaa'bbbb'cccc"; str.replace(/\'/gi,""); 처럼 사용하면 된다. 위 정규식 설명을 하면 - ' 을 정규식에 넣기위해 \' 을 사용하였고 - // 마지막에 g : 모든 문자열에서 pattern 검색 - i : 대소문자 구분안함 이렇게 replaceAll 처럼 사용한다. 더보기
Interpreter 방식의 javascript 또는 php 등에서 ++$i and $i++ 차이점 간단히 설명하면 ++$i is pre-increment whilst $i++ post-increment. - pre-increment: increment variable i first and then de-reference. 값이 먼저 증가 - post-increment: de-reference and then increment i. 값이 나중에 증가 ++$i //first increment $i then run line $i++ //first run line then increment $i 예문을 들면 더보기
보색 구하기 complementary color , Opposite Color COLOR OPPOSITE 00 11 22 33 44 55 66 77 88 99 AA BB CC DD EE FF 00 11 22 33 44 55 66 77 88 99 AA BB CC DD EE FF 00 11 22 33 44 55 66 77 88 99 AA BB CC DD EE FF - 소스 COLOR OPPOSITE 00 11 22 33 44 55 66 77 88 99 AA BB CC DD EE FF 00 11 22 33 44 55 66 77 88 99 AA BB CC DD EE FF 00 11 22 33 44 55 66 77 88 99 AA BB CC DD EE FF 출처 : http://www.colortools.net/color_complementary.html Opposite Color Tool.. 더보기
input 상자안에 기본값을 설정하고 focus가 들어왔을때 기본값을 없애주는 방법 JavaScript Clear Textfield Default Value onClick So basically if you have a text field with default text like “Enter Email Address Here” and you want it so that when the user clicks in it, the text disappears, this is the code to use. It goes one step further so that if you do not enter anything it puts the default text back and if there is something entered it doesn’t get tripped up and clear i.. 더보기
javascript 로 특정 이미지위를 클릭했을때 이미지상 클릭한 좌표값 구하기 위와 같이 하면 화면에서의 좌표가 아닌 이미지에서 좌표를 구할수있다. event.x ,event.y ( event.clientX ,event.clientY) 를 사용하면 해당 프레임내에서의 좌표를 event.screenX , event.screenY 를 사용하면 사용자 화면(브라우져)에서의 좌표값을 구할수있다. 더보기
키값을 임의로 지정하는 배열만들기 javascript key 값을 갇는 배열 만들기 var a = {'a':0, 'b':1, 'c':2}; var b = new Array(); b['a'] = 0; b['b'] = 1; b['c'] = 2; var c = new Object(); c.a = 0; c.b = 1; c.c = 2; 이 배열을 이용할때는 for (var key in a) { alert(a[key]) } 와 같은 형태로 이용할수있다. 더보기
두 날짜 사이의 날짜 수 계산 / 몇일인지 계산 f.e_sdate.value , f.e_edate.value 두 값은 2009-02-10 처럼 4자리 2자리 2자리 로 날짜 포맷이 정확한 상태일때로 가정한다. function calc_date_diff(){ if(f.e_sdate.value && f.e_edate.value){ var tmps = f.e_sdate.value.split("-"); var tmpe = f.e_edate.value.split("-"); var sDate = new Date(tmps[0],tmps[1]-1,tmps[2]); var eDate = new Date(tmpe[0],tmpe[1]-1,tmpe[2]); var days = Math.floor( ( parseInt(eDate.getTime()) - parseInt(sDa.. 더보기
날짜 유효성 검사 /***** * 날짜 유효성 검사 * return : boolean *****/ function check_date(year,month,day){ if( year.length == 4 && month.length > 0 && month.length 0 && day.length < 3 ){ month = month-1; // month - 1 한 의미에 주의 if(month.length == 1) month = '0' + month.toString(); if(day.length == 1) day = '0' + day.toString(); vDate = new Date(year,month,day); //vDate = new Date(); //vDate.setFullYear.. 더보기
Firefox 에서 this.parentElement.parentElement.rowIndex 동작하지 않는다. this.parentNode 으로 사용하면 FF , IE 에서 둘다 동작한다. parentElement 대신 parentNode 더보기
javascript convert HtmlEntities To Characters function convertHtmlEntitiesToCharacters(theStr) { var newDiv = document.createElement(newDiv); newDiv.innerHTML = theStr; return newDiv.innerHTML; //alert('Entities:\n' + theStr + '\n\nCharacters:\n' + newDiv.innerHTML); } ex) html 태그를 예를들어 와 같은것은 공백을 나타내는대 이것을 공백 문자 그대로 사용하기 위해 사용한다. html 상에 그냥 사용할때는 이런 변환작업이 필요없으나 javascript 등의 경고창에 사용하려면 문자그대로의 값이 필요하다 이럴때 사용하면 된다. 더보기

반응형