정규식으로 바꿨습니다.
많이 돌아 다니는 소스이긴 하지만..
<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, "");}
<!--
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>
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>
</BODY>
[이 게시물은 관리자님에 의해 2011-10-31 16:57:14 JavaScript에서 이동 됨]
게시판 목록
팁게시판
디자인과 관련된 유용한 정보를 공유하세요.
질문은 상단의 QA에서 해주시기 바랍니다.
질문은 상단의 QA에서 해주시기 바랍니다.
| 번호 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|
| 5827 | 9년 전 | 370 | ||
| 5826 | 9년 전 | 359 | ||
| 5825 | 9년 전 | 323 | ||
| 5824 | 9년 전 | 484 | ||
| 5823 | 9년 전 | 492 | ||
| 5822 | 9년 전 | 297 | ||
| 5821 | 9년 전 | 608 | ||
| 5820 | 9년 전 | 907 | ||
| 5819 | 9년 전 | 440 | ||
| 5818 | 9년 전 | 580 | ||
| 5817 |
|
9년 전 | 1382 | |
| 5816 | 9년 전 | 411 | ||
| 5815 | 9년 전 | 383 | ||
| 5814 | 9년 전 | 357 | ||
| 5813 |
|
9년 전 | 1151 | |
| 5812 | 9년 전 | 459 | ||
| 5811 | 9년 전 | 243 | ||
| 5810 | 9년 전 | 275 | ||
| 5809 | 9년 전 | 476 | ||
| 5808 | 9년 전 | 323 | ||
| 5807 | 9년 전 | 296 | ||
| 5806 | 9년 전 | 270 | ||
| 5805 | 9년 전 | 293 | ||
| 5804 | 9년 전 | 290 | ||
| 5803 | 9년 전 | 275 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기