복스리

직접만든 자바스크립트 Trim 함수입니다.

vbscript에서는 Trim 기능이 있는데 javascript에서는 Trim기능이 없어서..고민하다가. 한번 만들어봤습니다.
함수 사용법은 vbscript과 같구요
 
함수명은 trim , rtrim, ltrim 3개 입니다.. 작업하시면서 필요하실껍니다.
 
<HTML>
<HEAD>
<TITLE> 자바스크립드 완벽 Trim 함수 </TITLE>
<script language="javascript">
function ltrim(value)
{
  var LeftTrimValue = "";
  var i=0;
  if( value == "" )
        return "";
  strLen = value.length;
  while(i<strLen)
  {
    if(value.charAt(i) != " ") break;
    i++;
  }
  for(s=i;s<strLen;s++)
  {
    LeftTrimValue = LeftTrimValue + value.charAt(s);
  }
  return LeftTrimValue;
}
function rtrim(value)
{
  var RightTrimValue = "";
  if( value == "" )
        return "";
  strLen = value.length;
  --strLen;
  while( 0 <= strLen)
  {
    if(value.charAt(strLen) != " ") break;
    --strLen;
  }
  for(s=0;s<=strLen;s++)
  {
    RightTrimValue = RightTrimValue + value.charAt(s);
  }
  return RightTrimValue;
}
function trim(value)
{
  return rtrim(ltrim(value));
}
function test()
{
  switch(eval(form.sel.value))
  {
    case 1 :  alert("\"" + trim(form.ok.value)  + "\"" ); break;
    case 2 :  alert("\"" + rtrim(form.ok.value) + "\"" ); break;
    case 3 :  alert("\"" + ltrim(form.ok.value) + "\"" ); break;
  }
}
</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="button" value="확인" onclick="test()"><br>
</form>
</BODY>
</HTML>
 
긁어다가 textbox에 글 넣구 스페이스 넣구 한번 동작해보세요
 
[이 게시물은 관리자님에 의해 2011-10-31 16:57:14 JavaScript에서 이동 됨]
|

댓글 1개

속도빠릅니다.
댓글을 작성하시려면 로그인이 필요합니다. 로그인

프로그램

+
제목 글쓴이 날짜 조회
18년 전 조회 2,221
18년 전 조회 2,525
18년 전 조회 1,769
18년 전 조회 2,097
18년 전 조회 1,985
18년 전 조회 2,503
18년 전 조회 1,921
18년 전 조회 1,714
18년 전 조회 1,744
18년 전 조회 1,721
18년 전 조회 2,753
18년 전 조회 1,544
18년 전 조회 5,663
18년 전 조회 2,392
18년 전 조회 1,660
18년 전 조회 4,705
18년 전 조회 2,050
18년 전 조회 4,838
18년 전 조회 3,185
18년 전 조회 2,128
18년 전 조회 1,822
18년 전 조회 2,094
18년 전 조회 1,717
18년 전 조회 1,834
18년 전 조회 1,831
18년 전 조회 2,474
18년 전 조회 3,492
18년 전 조회 5,966
18년 전 조회 3,858
18년 전 조회 3,052
18년 전 조회 2,126
18년 전 조회 2,398
18년 전 조회 2,179
18년 전 조회 2,300
18년 전 조회 2,397
18년 전 조회 2,836
18년 전 조회 2,531
18년 전 조회 1,986
18년 전 조회 3,121
18년 전 조회 3,582
18년 전 조회 3,830
18년 전 조회 3,331
18년 전 조회 3,371
18년 전 조회 2,557
18년 전 조회 2,460
18년 전 조회 2,447
18년 전 조회 2,316
18년 전 조회 2,550
18년 전 조회 3,846
18년 전 조회 3,648
18년 전 조회 2,077
18년 전 조회 2,015
18년 전 조회 1,550
18년 전 조회 3,882
18년 전 조회 5,885
18년 전 조회 6,982
18년 전 조회 2,462
18년 전 조회 2,706
18년 전 조회 4,163
18년 전 조회 2,169
18년 전 조회 3,613
18년 전 조회 2,869
18년 전 조회 2,725
18년 전 조회 2,195
18년 전 조회 2,460
18년 전 조회 2,589
18년 전 조회 3,083
18년 전 조회 3,727
18년 전 조회 3,267
18년 전 조회 2,773
18년 전 조회 2,268
18년 전 조회 2,937
18년 전 조회 3,027
18년 전 조회 2,536
18년 전 조회 2,291
18년 전 조회 3,325
18년 전 조회 4,847
18년 전 조회 5,066
18년 전 조회 2,288
18년 전 조회 2,182
18년 전 조회 4,992
18년 전 조회 8,955
18년 전 조회 2,041
18년 전 조회 4,919
18년 전 조회 4,358
18년 전 조회 2,601
18년 전 조회 4,956
18년 전 조회 2,783
18년 전 조회 3,663
18년 전 조회 2,615
19년 전 조회 3,428
19년 전 조회 1,939
19년 전 조회 5,369
19년 전 조회 1,688
19년 전 조회 6,047
19년 전 조회 2,866
19년 전 조회 6,032
19년 전 조회 6,826
19년 전 조회 3,719
19년 전 조회 2,199
🐛 버그신고