본문 바로가기

잼있냐JavaScript

javascript - replace("find","replacestr") 자바 스크립트에서 replace() 함수는 의 기능에서 반복되는 문자가 있을 시 예를 들어 (-) 하이픈 --;; 날짜에 2008-11-06 이라는 날짜 문자에서 - 을 모두 '' 로 처리 하고 싶다고 가정한다면 JAVA 에서는 replaceAll 메소드가 있지만.. javascript 에서는 그런 메소드가 없다... 이럴 때는... 아래 예재를 참고 하길 바란다. Example 3 - Global Search In the following example we will perform a global match, and the word Microsoft will be replaced each time it is found: The output of the code above will be: Welcome .. 더보기
checkbox radio select 유용한 스크립트 7 /* * checkbox object checked 속성 체크 */ function all_check(obj, true_or_false) { if (obj) { if (obj.length) { for (var i=0; i 더보기
메시지 관련 스크립트 - 유용한 스크립트 6 /* * 메세지를 출력후에 이전 페이지로 되돌린다. */ function alert_back(msg) { alert(msg); history.back(); } /* * 메세지를 출력후에 특정 페이지로 이동한다. */ function alert_location(msg, url) { alert(msg); location.href = url; } /* * 메세지를 출력후에 특정 객체를 Focus 한다. */ function alert_focus(msg, obj) { alert(msg); if(obj) obj.focus(); } 더보기
날짜 관련 스크립트 - 유용한 스크립트 5 /* * 입력한 날짜(yyyyMMdd)가 유효한 날짜인지 검사 */ function is_valid_date(date_str) { var yyyyMMdd = String(date_str); var year = yyyyMMdd.substring(0,4); var month = yyyyMMdd.substring(4,6); var day = yyyyMMdd.substring(6,8); if (!is_number(date_str) || date_str.length!=8) return false; if (Number(month)>12 || Number(month) 8) time2 = to_date2(date2).getTime() - y1970; else time2 = to_date(date2).getTime() .. 더보기
쿠키 제어 -유용한 스크립트 4 /* * 주어진 이름으로 된 쿠키 값을 반환 */ function get_cookie(name) { var cookies = document.cookie.split("; "); for (var i=0; i 더보기
문자열 변환 및 숫자열 변환 관련 - 유용한 스크립트 3 /* * 문자열의 Byte 수를 반환한다. */ function get_byte(str) { var len = 0; for (var idx=0; idx 1) return data.join(""); else return data[0].split(".")[0]; } /* * 1000단위 콤마로 구분된 문자열를 숫자로 반환 */ function money_to_num(str) { var num = replace_str(String(str), ",", ""); return Number(num); } /* * 숫자 num을 n자릿수까지 반올림 */ function round_x(num, n) { // 1234.675, 2 -> 1234.68 var i = Math.pow(10, n); return Math.rou.. 더보기
유효성검사 스크립트 - 유용한 자바스크립트 2 /* * 숫자로만 이루어진 문자열인지 검사 * cf) 음수부호는 포함하지 않음 */ function is_number(x) { var reg = /^\d+$/; return reg.test(x); } /* * 부동소수점 숫자인지 음수부호도 포함하여 검사 */ function is_double(x) { var reg = /^[-|+]?\d+\.?\d*$/; return reg.test(x); } /* * 부동소수점 숫자인지 검사 * cf) 음수부호는 포함하지 않음 */ function is_double_plus(x) { var reg = /^\d+\.?\d*$/; return reg.test(x); } /* * 정수인지 음수부호도 포함하여 검사 */ function is_integer(x) { var re.. 더보기
문자열 스크립트 - 유용한 자바스크립트 1 /* * 왼쪽에 위치한 whitespace 문자를 제거 */ function ltrim(str) { return str.replace(/^\s+/, ""); } /* * 오른쪽에 위치한 whitespace 문자를 제거 */ function rtrim(str) { return str.replace(/\s+$/, ""); } /* * 양쪽의 whitespace 문자를 제거 */ function trim(str) { return rtrim(ltrim(str)); } /* * 주어진 문자열의 왼쪽을 padding 문자로 채운다 */ function lpad(str, n, padding) { if (str.length >= n) return str; else { var len = n - str.length; va.. 더보기
야구게임 1. you have to find out Three Number!! filst you choose three number and input number to each blank And push '송구' button!! and you find both strike count and ball count Strike means Number is exist and position is right Ball means Number is exist and position is wrong 회수: 정답: 송구: 더보기
시를 출력해주는 클래스 위 Poem(시)class를 컴파일 하시겠습니까? 더보기