달력

4

« 2024/4 »

  • 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
2009. 7. 9. 20:56

JavaScript String replace 그거/Tech2009. 7. 9. 20:56


오랜만에 JavaScript를 했더니.. 머리 쥐난다. -_-;
예전에 표준을 지키지 않고 코딩(?)하던 이후로는 거의 처음하는것 같은데..
좀 헤맸다는. ㅎㅎ

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>
<head><title>TEST</title>
<script language="JavaScript">
<!--
function gogo() {
 var str="&lt;font size='3'&gt;This is test&lt;/font&gt;"
 // str에서 &lt; 를 모두 찾아서 < 로 치환
 var str2=str.replace(/\&lt;/g, "<");
 // str에서 &gt; 를 모두 찾아서 > 로 치환

 var str2=str2.replace(/\&gt;/g, ">");

 document.getElementById("str").value=str;
 document.getElementById("content").value=str2;
}
//-->
</script>
</head>
<body onLoad="javascript:gogo()">
 <textarea cols=50 rows=5 id="str"></textarea>
<br>
↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓
<form name="frm">
 <textarea cols=50 rows=5 id="content"></textarea>
</form>
</body>
</html>

# 결과

:
Posted by 뽀기