많이 쓰이는 자바스크립트

/*---------------------------------------------

* String 문자 자르기.
---------------------------------------------*/
String.prototype.cut = function(len) {
var str = this;
var l = 0;
for (var i=0; i<str.length; i++) {
l += (str.charCodeAt(i) > 128) ? 2 : 1;
if (l > len) return str.substring(0,i);
}
return str;
}

/*---------------------------------------------

* String 공백 지우기.
---------------------------------------------*/
String.prototype.trim = function(){
// Use a regular expression to replace leading and trailing
// spaces with the empty string
return this.replace(/(^\s*)|(\s*$)/g, "");
}

/*---------------------------------------------
* String 총 바이트 수 구하기.
---------------------------------------------*/
String.prototype.bytes = function() {
var str = this;
var l = 0;
for (var i=0; i<str.length; i++) l += (str.charCodeAt(i) > 128) ? 2 : 1;
return l;
}

/*---------------------------------------------
* iframe의 height를 body의 내용만큼 자동으로 늘려줌.
---------------------------------------------*/
function resizeRetry(){
if(ifrContents.document.body.readyState == "complete"){
clearInterval(ifrContentsTimer);
}
else{
resizeFrame(ifrContents.name);
}
}

var ifrContentsTimer;
var ifrContents;

function resizeFrame(name){

var oBody = document.body;
var oFrame = parent.document.all(name);
ifrContents = oFrame;
var min_height = 613; //iframe의 최소높이(너무 작아지는 걸 막기위함, 픽셀단위, 편집가능)
var min_width = 540; //iframe의 최소너비
var i_height = oBody.scrollHeight + 10;

var i_width = oBody.scrollWidth + (oBody.offsetWidth-oBody.clientWidth);

if(i_height < min_height) i_height = min_height;
if(i_width < min_width) i_width = min_width;
oFrame.style.height = i_height;
ifrContentsTimer = setInterval("resizeRetry()",100);
}

/*---------------------------------------------
* 클립보드에 해당 내용을 복사함.
---------------------------------------------*/

function setClipBoardText(strValue){
window.clipboardData.setData('Text', strValue);
alert("" + strValue +" \n\n위 내용이 복사되었습니다.\n\nCtrl + v 키를 사용하여, 붙여 넣기를 사용하실 수 있습니다.");
}


/*---------------------------------------------
select 에서 기존의 선택 값이 선택되게
----------------------------------------------*/
function selOrign(frm,val){
for(i=0; i < frm.length ; i++){
if(frm.options[i].value == val){
frm.options.selectedIndex = i ;
return;
}
}
}

/*---------------------------------------------
checkbox 에서 기존의 선택 값이 선택되게
----------------------------------------------*/
function chkboxOrign(frm,val){
if(frm.length == null){
if(frm.value == val)
frm.checked = true;
}else{
for(i=0;i<frm.length;i++){
if(frm[i].value == val){
frm[i].checked = true;
}
}
return;
}
}

function chkboxOrign_multi(frm,objchk,val){
var i = 0;
for(i=0;i<frm.elements.length;i++){
if(frm.elements[i].name == objchk){
if(frm.elements[i].value == val){
frm.elements[i].checked = true;
}
}
}
}

/*---------------------------------------------
radio 에서 기존의 선택 값이 선택되게
----------------------------------------------*/
function radioOrign(frm,val){
for(i=0; i < frm.length ; i++){
if(frm[i].value == val){
frm[i].checked = true ;
return ;
}
}
}

/*---------------------------------------------
숫자만 입력받기
예) onKeyDown="return onlyNum();"
----------------------------------------------*/
function onlyNum(){
if(
(event.keyCode >= 48 && event.keyCode <=57) ||
(event.keyCode >= 96 && event.keyCode <=105) ||
(event.keyCode >= 37 && event.keyCode <=40) ||
event.keyCode == 9 ||
event.keyCode == 8 ||
event.keyCode == 46
){
//48-57(0-9)
//96-105(키패드0-9)
//8 : backspace
//46 : delete key
//9 :tab
//37-40 : left, up, right, down
event.returnValue=true;
}
else{
//alert('숫자만 입력 가능합니다.');
event.returnValue=false;
}
}

/*---------------------------------------------
지정된 길이반큼만 입력받기
예) onKeyUp="return checkAllowLength(현재숫자보여지는객체,숫자셀객체 ,80);" onKeyDown="return checkAllowLength(현재숫자보여지는객체,숫자셀객체 ,80);"
----------------------------------------------*/

function checkAllowLength(objView, objTar, max_cnt){
if(event.keyCode > 31 || event.keyCode == "") {
if(objTar.value.bytes() > max_cnt){
alert("최대 " + max_cnt + "byte를 넘길 수 없습니다.");
objTar.value = objTar.value.cut(max_cnt);
}
}
objView.value = objTar.value.bytes();
}


/*--------------------------------------------
이미지 리사이즈
---------------------------------------------*/
function resizeImg(imgObj, max_width, max_height){

var dst_width;
var dst_height;
var img_width;
var img_height;

img_width = parseInt(imgObj.width);
img_height = parseInt(imgObj.height);

if(img_width == 0 || img_height == 0){
imgObj.style.display = '';
return false;
}

// 가로비율 우선으로 시작
if(img_width > max_width || img_height > max_height) {
// 가로기준으로 리사이즈
dst_width = max_width;
dst_height = Math.ceil((max_width / img_width) * img_height);

// 세로가 max_height 를 벗어났을 때
if(dst_height > max_height) {
dst_height = max_height;
dst_width = Math.ceil((max_height / img_height) * img_width);
}

imgObj.width = dst_width;
imgObj.height = dst_height;
}
// 가로비율 우선으로 끝

imgObj.style.display = '';

return true;
}
/*---------------------------------------------
xml data 읽어오기
----------------------------------------------*/
function getXmlHttpRequest(_url, _param){
var objXmlConn;
try{objXmlConn = new ActiveXObject("Msxml2.XMLHTTP.3.0");}
catch(e){try{objXmlConn = new ActiveXObject("Microsoft.XMLHTTP");}catch(oc){objXmlConn = null;}}

if(!objXmlConn && typeof XMLHttpRequest != "undefined") objXmlConn = new XMLHttpRequest();

objXmlConn.open("GET", _url + "?" + _param, false);
objXmlConn.send(null);

//code|message 형태로 리턴
return objXmlConn.responseText.trim().split("|");
}


/*---------------------------------------------------
cookie 설정
-------------------------------------------------------*/

function getCookieVal (offset) {
var endstr = document.cookie.indexOf (";", offset);
if (endstr == -1) endstr = document.cookie.length;
return unescape(document.cookie.substring(offset, endstr));
}

function GetCookie (name) {
var arg = name + "=";
var alen = arg.length;
var clen = document.cookie.length;
var i = 0;
while (i < clen) { //while open
var j = i + alen;
if (document.cookie.substring(i, j) == arg)
return getCookieVal (j);
i = document.cookie.indexOf(" ", i) + 1;
if (i == 0) break;
} //while close
return null;
}

function SetCookie (name, value) {
var argv = SetCookie.arguments;
var argc = SetCookie.arguments.length;
var expires = (2 < argc) ? argv[2] : null;
var path = (3 < argc) ? argv[3] : null;
var domain = (4 < argc) ? argv[4] : null;
var secure = (5 < argc) ? argv[5] : false;
document.cookie = name + "=" + escape (value) +
((expires == null) ? "" :
("; expires=" + expires.toGMTString())) +
((path == null) ? "" : ("; path=" + path)) +
((domain == null) ? "" : ("; domain=" + domain)) +
((secure == true) ? "; secure" : "");
}

/* ---------------------------------------------
* 함수명 : checkSpecialChar
* 설 명 : 특수문자 체크
* 예) if(!checkSpecialChar()) return;
---------------------------------------------*/
function checkSpecialChar(_obj){
if(_obj.value.search(/[\",\',<,>]/g) >= 0) {
alert("문자열에 특수문자( \", ', <, > )가 있습니다.\n특수문자를 제거하여 주십시오!");
_obj.select();
_obj.focus();
}
}<div class='small'>[이 게시물은 관리자님에 의해 2011-10-31 16:57:14 JavaScript에서 이동 됨]</div>
|
댓글을 작성하시려면 로그인이 필요합니다.

프로그램

태그 필터 (최대 3개) 전체 개발자 소스 기타 mysql 팁자료실 javascript php linux flash 정규표현식 jquery node.js mobile 웹서버 os 프로그램 강좌 썸네일 이미지관련 도로명주소 그누보드5 기획자 견적서 계약서 기획서 마케팅 제안서 seo 통계 서식 통계자료 퍼블리셔 html css 반응형 웹접근성 퍼블리싱 표준화 반응형웹 홈페이지기초 부트스트랩 angularjs 포럼 스크린리더 센스리더 개발자톡 개발자팁 퍼블리셔톡 퍼블리셔팁 기획자톡 기획자팁 프로그램강좌 퍼블리싱강좌
+
제목 글쓴이 날짜 조회
19년 전 조회 2,423
19년 전 조회 3,979
19년 전 조회 5,362
19년 전 조회 2,704
19년 전 조회 1,761
19년 전 조회 1,598
19년 전 조회 1,543
19년 전 조회 1,819
19년 전 조회 1,819
19년 전 조회 1,824
19년 전 조회 1,742
19년 전 조회 2,538
19년 전 조회 2,337
19년 전 조회 3,499
19년 전 조회 2,628
19년 전 조회 2,599
19년 전 조회 3,441
19년 전 조회 4,660
19년 전 조회 3,000
19년 전 조회 2,829
19년 전 조회 3,379
19년 전 조회 6,315
19년 전 조회 2,214
19년 전 조회 2,018
19년 전 조회 1,975
19년 전 조회 2,032
19년 전 조회 3,219
19년 전 조회 2,294
19년 전 조회 1,978
19년 전 조회 1,661
19년 전 조회 2,113
19년 전 조회 3,396
19년 전 조회 3,257
19년 전 조회 1,939
19년 전 조회 1,516
19년 전 조회 3,208
19년 전 조회 2,078
19년 전 조회 1,646
19년 전 조회 2,862
19년 전 조회 2,000
19년 전 조회 1,879
19년 전 조회 1,841
19년 전 조회 1,804
19년 전 조회 2,232
19년 전 조회 2,651
19년 전 조회 1,812
19년 전 조회 1,548
19년 전 조회 1,560
19년 전 조회 1,490
19년 전 조회 3,248
19년 전 조회 2,938
19년 전 조회 1,694
19년 전 조회 3,432
19년 전 조회 1,856
19년 전 조회 1,512
19년 전 조회 1,974
19년 전 조회 2,118
19년 전 조회 1,663
19년 전 조회 2,359
19년 전 조회 2,010
19년 전 조회 1,625
19년 전 조회 1,805
19년 전 조회 2,066
19년 전 조회 1,813
19년 전 조회 1,611
19년 전 조회 1,676
19년 전 조회 3,148
19년 전 조회 2,016
19년 전 조회 1,883
19년 전 조회 4,383
19년 전 조회 5,013
19년 전 조회 3,177
19년 전 조회 2,913
19년 전 조회 3,519
19년 전 조회 2,059
19년 전 조회 2,413
19년 전 조회 2,706
19년 전 조회 2,784
19년 전 조회 2,371
19년 전 조회 1,637
19년 전 조회 3,403
19년 전 조회 1,996
19년 전 조회 2,405
19년 전 조회 2,467
19년 전 조회 2,896
19년 전 조회 5,222
19년 전 조회 2,504
19년 전 조회 3,347
19년 전 조회 4,287
19년 전 조회 2,525
19년 전 조회 2,480
19년 전 조회 4,058
19년 전 조회 2,771
19년 전 조회 3,010
19년 전 조회 2,227
19년 전 조회 2,238
19년 전 조회 2,019
19년 전 조회 3,304
19년 전 조회 2,138
19년 전 조회 2,813