블로그 이미지
암초보

calendar

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

Notice

Tag

04-30 02:26

'프로그래밍/JavaScript'에 해당되는 글 18

  1. 2009.10.15 텍스트박스 enter시 자동 submit되는 현상
  2. 2009.09.30 날짜 계산관련 스크립트
  3. 2009.09.28 유용한팁.
  4. 2009.09.28 자바스크립트 trim()
  5. 2009.08.29 window.open() 함수 사용시 주소표시줄 설정.
  6. 2009.08.23 LiteBox2
  7. 2009.07.20 getElementById 할 때..
  8. 2009.07.01 eval()함수1
2009. 10. 15. 16:21 프로그래밍/JavaScript

form 안에 텍스트 박스가 한개이고,
 
엔터를 친다면 onsubmit 이벤트가 발생한다.

해결 방법은,

onsubmit="return false"

를 추가하면 된다.

'프로그래밍 > JavaScript' 카테고리의 다른 글

IE6 에서 href 에 한글 사용시...  (0) 2010.09.27
날짜 유효성 체크 (정규표현식)  (1) 2010.03.05
날짜 계산관련 스크립트  (0) 2009.09.30
유용한팁.  (0) 2009.09.28
자바스크립트 trim()  (0) 2009.09.28
posted by 암초보
2009. 9. 30. 09:32 프로그래밍/JavaScript

function setDateRange(selected_date_range){
  if(selected_date_range.value=="ALL"){
   document.search.startDate.value = "";
   document.search.endDate.value = "";
  }
  else if(selected_date_range.value=="WEEK"){
   document.search.startDate.value = getNextDate(-7);
   document.search.endDate.value = getNextDate(0);
  }
  else if(selected_date_range.value=="MONTH"){
   document.search.startDate.value = getNextDate(-30);
   document.search.endDate.value = getNextDate(0);
  }else  if(selected_date_range.value=="SET"){
   document.search.startDate.value = getNextDate(-(365*5));//기본 5년전부터.
   document.search.endDate.value = getNextDate(0);
  }
 }
 
 function setDateRangeButton(){
  if(document.search.startDate.value == ""){
   document.search.startDate.value = getNextDate(-(365*5));
   document.search.endDate.value = getNextDate(0);
  }
  document.search.date_range[3].checked= "checked";
 }
 
 function getNextDate(t){
  var current_time = new Date();
  var result = current_time.valueOf()+1000*60*60*24*(t);
  var result_time = new Date(result);
  var yy = result_time.getFullYear();
  var mm = result_time.getMonth()+1;
  if(mm<10)
   mm = "0"+mm;
  var dd = result_time.getDate();
  var date_string = yy+"-"+mm+"-"+dd;
  return date_string;
 }
posted by 암초보
2009. 9. 28. 20:27 프로그래밍/JavaScript
// 자바스크립트 긁기

javascript:function r(d){d.oncontextmenu=null;d.onselectstart=null;d.ondragstart=null;d.onkeydown=null;d.onmousedown=null; d.body.oncontextmenu=null;d.body.onselectstart=null;d.body.ondragstart=null;d.body.onkeydown=null; d.body.onmousedown=null;};function unify(w){r(w.document);if(w.frames.length>0){for(var i=0;i<w.frames.length;i++){try{unify(w.frames[i].window);}catch(e){}};};};unify(self);alert("ok");


posted by 암초보
2009. 9. 28. 20:23 프로그래밍/JavaScript

var str = "';

str.replace(/(^\s*)|(\s*$)/g,"");//공백제거됨

 

 /* =================================================================
  앞/뒤 공백 제거
 ================================================================= */

 String.prototype.trim = function() {
  return this.replace(/\s/g, "");
 }

 

 /* =================================================================
  앞 공백 제거
 ================================================================= */

 String.prototype.ltrim = function() {

  var i, j = 0;
  var objstr

  for (i = 0; i < this.length; i++) {

   if (this.charAt(i) == ' ') j = j + 1;
   else break;
  }

  return this.substr(j, this.length - j + 1) 
 }

 /* =================================================================
  뒤 공백 제거
 ================================================================= */

 String.prototype.rtrim = function() {

  var i, j = 0;

  for (i = this.length - 1; i >= 0; i--) {

   if (this.charAt(i) == ' ') j = j + 1;
   else break;
  }

  return this.substr(0, this.length - j);
 }

'프로그래밍 > JavaScript' 카테고리의 다른 글

날짜 계산관련 스크립트  (0) 2009.09.30
유용한팁.  (0) 2009.09.28
window.open() 함수 사용시 주소표시줄 설정.  (0) 2009.08.29
LiteBox2  (0) 2009.08.23
getElementById 할 때..  (0) 2009.07.20
posted by 암초보
2009. 8. 29. 13:49 프로그래밍/JavaScript
window.open(URL, 창이름, 설정값)

설정값에 location=no 추가하면 된다.

(새창을 열때, 주소표시줄로 포커스가 이동하는 문제 해결)

'프로그래밍 > JavaScript' 카테고리의 다른 글

유용한팁.  (0) 2009.09.28
자바스크립트 trim()  (0) 2009.09.28
LiteBox2  (0) 2009.08.23
getElementById 할 때..  (0) 2009.07.20
eval()함수  (1) 2009.07.01
posted by 암초보
2009. 8. 23. 16:08 프로그래밍/JavaScript

'프로그래밍 > JavaScript' 카테고리의 다른 글

유용한팁.  (0) 2009.09.28
자바스크립트 trim()  (0) 2009.09.28
window.open() 함수 사용시 주소표시줄 설정.  (0) 2009.08.29
getElementById 할 때..  (0) 2009.07.20
eval()함수  (1) 2009.07.01
posted by 암초보
2009. 7. 20. 02:20 프로그래밍/JavaScript

이전 버전에서는 name과 id 모두 가능했으나,

IE8에서는 id로만 가능하다.

'프로그래밍 > JavaScript' 카테고리의 다른 글

유용한팁.  (0) 2009.09.28
자바스크립트 trim()  (0) 2009.09.28
window.open() 함수 사용시 주소표시줄 설정.  (0) 2009.08.29
LiteBox2  (0) 2009.08.23
eval()함수  (1) 2009.07.01
posted by 암초보
2009. 7. 1. 09:21 프로그래밍/JavaScript
eval() 함수는 eval안에 있는 문자형 수식을 계산하거나
문자형 숫자를 숫자형 숫자로 바꿔주는 함수다.
 

 
- 소스 설명 -
 
(참고로 소스는 오른쪽 상단에 첨부하였으니 열기로 열어 테스트를 통해 쉽게 이해하자.)
 
소스는 폼에 있는 데이터를 가져와 실행하는 메소드 3개로 구성되어 있다.
첫번째 메소드 evala() 에서는 eval1이라는 text의 값을 가져와 eval함수를 이용 수식을 계산해주는 함수다. 5*5+4 로 기본값으로 넣은 것을 계산하여 경고창에 29라는 숫자를 보여준다.
 
두번째 메소드 evalb()는 eval2,eval3의 text값을 가져와 더하는 예제인데 우리가 폼에 있는 값을 그냥 가져와 더하면10+10 = 1010 이 된다. 이것은 숫자가 아닌 문자형태로 값을 가져오기 때문에 일어나는 현상이다.숫자로 계산하기 위해서는 세번째 메소드 evalc()와 같이 eval함수를 써숫자형으로 변경해줘야지만 10+10 = 20 이 나오게 된다.
 
eval은 Java에서 Interger.parseInt와 비슷하다.
String a = "123";
String b = "456";
int c;
c = Integer.parseInt(a) + Integer.parseInt(b);
System.out.println(c);

 


'프로그래밍 > JavaScript' 카테고리의 다른 글

유용한팁.  (0) 2009.09.28
자바스크립트 trim()  (0) 2009.09.28
window.open() 함수 사용시 주소표시줄 설정.  (0) 2009.08.29
LiteBox2  (0) 2009.08.23
getElementById 할 때..  (0) 2009.07.20
posted by 암초보
prev 1 2 next