[英]jQuery string formatting issue
I'm trying to achieve the effect shown here: 我正在尝试达到此处所示的效果:
http://jsfiddle.net/kyromedia/BnRfJ/ http://jsfiddle.net/kyromedia/BnRfJ/
and get it to work on here: 并在这里进行工作:
http://jsfiddle.net/kyromedia/GJx3D/3/ http://jsfiddle.net/kyromedia/GJx3D/3/
Here is my jQuery: 这是我的jQuery:
$(".carousel_dp_home_price").each(function (index, elem) {
var price = $(elem);
var oldHtml = price.html();
var newHtml = oldHtml.replace(/(\.\d+)$/,'<span class="carousel_dp_home_cents">$1</span>').replace('$', '');
price.html(newHtml);
});
Basically the script takes a string from a div with defined class, removes the "$" symbol and puts the decimal point and all characters after it in a span. 基本上,脚本从具有已定义类的div中获取字符串,删除“ $”符号,并将小数点及其后的所有字符放在一个跨度中。
I'm not able to get the cents span to be generated correctly. 我无法正确生成美分跨度。
After enabling the JQuery library, you should either remove the $ (end-of-string marker) from your regexp, or remove any newline after the prices themselves (in the original version they are not present): 启用JQuery库后,您应该从正则表达式中删除$(字符串结尾标记),或者在价格本身之后删除任何换行符(在原始版本中不存在):
/(\.\d+)/
Please take a look: http://jsfiddle.net/Q3FuR/ . 请看一下: http : //jsfiddle.net/Q3FuR/ 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.