js中replace方法的语法

来源:互联网 发布:排课表的软件 编辑:程序博客网 时间:2024/06/06 03:02

replace方法的语法是:
string.replace(rgExp, replaceText)
其中string是当前要处理的字符串(string),reExp可以是正则表达式对象(RegExp)也可以是一个字符串,replaceText是替代字符串。
举个小栗子
通俗易懂的方法,详细查看官方文档

    <script>        var str="http://127.0.0.1:9080/index.html?id=123";           //替换字符串中'index.html' 为'app.login.html'    //返回一个新的字符串 http://127.0.0.1:9080/app.login.html?id=123    var newstr=str.replace("index.html","app.login.html");            console.log(newstr)       </script>
原创粉丝点击