게

아래에 있는 trim을 보다가 조금 수정해봤습니다.

· 2007-02-22 (목) 18:01:34 · 2082
정규식으로 바꿨습니다.
많이 돌아 다니는 소스이긴 하지만..
 
<SCRIPT LANGUAGE="JavaScript">
<!--
 String.prototype.trim = function() {return this.replace(/(^\s*)|(\s*$)/g, "");}
 String.prototype.ltrim = function() {return this.replace(/(^\s*)/g, "");}
 String.prototype.rtrim = function() {return this.replace(/(\s*$)/g, "");}
 
 function res(){
  if(document.form.sel.value == "1")
   document.form.rep.value = document.form.ok.value.trim();
  if(document.form.sel.value == "2")
   document.form.rep.value = document.form.ok.value.rtrim();
  if(document.form.sel.value == "3")
   document.form.rep.value = document.form.ok.value.ltrim();
 }
//-->
</SCRIPT>
</HEAD>
<BODY>

<form name="form">
  <select name="sel">
    <option value="1">Trim</option>
    <option value="2">rTrim</option>
    <option value="3">lTrim</option>
  </select>
  <input type="text" name="ok" >
  <input type="text" name="rep" >
  <input type="button" value="확인" onclick="res();"><br>
</form>
</BODY>
[이 게시물은 관리자님에 의해 2011-10-31 16:57:14 JavaScript에서 이동 됨]
댓글을 작성하시려면 로그인이 필요합니다.

팁게시판

6,077건

디자인과 관련된 유용한 정보를 공유하세요. 질문은 상단의 QA에서 해주시기 바랍니다.

+
제목 글쓴이 날짜 조회
07-03-13 조회 4,270
07-03-13 조회 2,434
07-03-08 조회 3,414
07-03-08 조회 2,854
07-03-08 조회 2,196
07-03-08 조회 2,984
07-03-05 조회 3,239
07-03-04 조회 1,835
07-03-01 조회 4,780
07-02-28 조회 2,135
07-02-27 조회 3,271
07-02-26 조회 2,213
07-02-26 조회 1,924
07-02-23 조회 2,488
07-02-23 조회 2,378
07-02-22 조회 2,927
07-02-22 조회 2,635
07-02-19 조회 2,634
07-02-17 조회 3,744
07-02-14 조회 7,078
07-02-12 조회 2,803
07-02-10 조회 2,295
07-02-02 조회 2,639
07-01-31 조회 2,290
07-01-29 조회 2,150