使用Javascript和jQuery替换使用字符串替换的冒号 [英] Replacing a colon using string replace using Javascript and jQuery

查看:386
本文介绍了使用Javascript和jQuery替换使用字符串替换的冒号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个我想要操作的简单字符串:

I have a simple string that I'm trying to manipulate:


您的订单将很快得到处理:

Your order will be processed soon:

我使用以下方法获取字符串:

I grab the string using:

var html = jQuery('.checkout td h4').html();

然后尝试使用以下代码替换':':

I then try to replace the ':' using:

html.replace(":", ".");

当我将其打印到控制台时,字符串与原始字符串相同。我还尝试通过执行以下操作确保 html 变量的类型为string:

When I print it out to the console, the string is the same as the original string. I've also tried making sure that the html variable is of type "string" by doing the following:

html = html + "";

这没有任何作用。在搜索时,似乎替换函数执行RegEx搜索,并且:字符可能具有特殊含义。我不知道如何解决这个问题。有人可以帮助我摆脱这个stinkin'冒号吗?

That doesn't do anything. In searching around, it seems that the replace function does a RegEx search and that the ":" character might have a special meaning. I do not know how to fix this. Can someone help me get rid of this stinkin' colon?

推荐答案

替换函数返回一个带有替换的新字符串。

Javascript字符串是不可变的—它不能修改原始字符串。

The replace function returns a new string with the replacements made.
Javascript strings are immutable—it cannot modify the original string.

你需要写 html = html.replace(:,。);

这篇关于使用Javascript和jQuery替换使用字符串替换的冒号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆