เป็นเทคนิคที่หลายคนอาจรู้ และหลายคนที่ไม่รู้ครับ
1
2
3
4
5
6
7
8
9
10
11
| <script type="text/javascript">
var str= "Joke";
var oldString = "Hello username! I hope you enjoy Hello your Hello stay username username username.";
var newString = oldString .replace(/username/g, str);
document.write("Old string = " + oldString );
document.write("<br />New string = " + newString );
</script> |
<script type="text/javascript">
var str= "Joke";
var oldString = "Hello username! I hope you enjoy Hello your Hello stay username username username.";
var newString = oldString .replace(/username/g, str);
document.write("Old string = " + oldString );
document.write("<br />New string = " + newString );
</script>
ผลลัพธ์
1
2
| Old string = Hello username! I hope you enjoy Hello your Hello stay username username username.
New string = Hello Joke! I hope you enjoy Hello your Hello stay Joke Joke Joke. |
Old string = Hello username! I hope you enjoy Hello your Hello stay username username username.
New string = Hello Joke! I hope you enjoy Hello your Hello stay Joke Joke Joke.
เทคนิคง่ายๆ บางครั้งเรอาจไม่รู้ หรือมองข้ามไปครับ
This entry was posted
on Sunday, June 13th, 2010 at 12:42 am and is filed under มุม JavaScript.
You can follow any responses to this entry through the RSS 2.0 feed.
Both comments and pings are currently closed.
July 25th, 2013 at 4:38 pm
[…] @JDev เลยเอาวิธีการมาแบ่งปันครับ […]