js中replace的用法(兩種常用舉例,還有好多用法不一一列舉)

1、替換特定字符

<html>
<body>

<script type="text/javascript">

var str="Visit Microsoft!"
document.write(str.replace(/Microsoft/,"W3School"))

</script>
</body>
</html>
2、全局替換

<html>
<body>

<script type="text/javascript">

var str="Welcome to Microsoft! ";
str=str + "We are proud to announce that Microsoft has ";
str=str + "one of the largest Web Developers sites in the world.";
document.write(str.replace(/Microsoft/g, "W3School"));

</script>

</body>
</html>


js中replace的用法(兩種常用舉例,還有好多用法不一一列舉)

http://www.a5idc.com/thread-142867-1-1.html

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章