简体   繁体   English

如何从包装成百分号的javascript变量中删除美元符号?

[英]How can I remove the dollar sign from a javascript variable wrapped in percentage signs?

I'm looking at a shopping cart that echos a variable when it is wrapped with two percentage signs. 我正在看一个购物车,当它用两个百分比符号包裹时,它会回显一个变量。

For example, on an html page %%Amount%% would echo something like $4.50. 例如,在html页面上,%% Amount %%会显示类似$ 4.50的字样。

In javascript, I have something that reads: 在javascript中,我看到的内容是:

var tag_params = {
prodid: '',
pagetype: 'cart',
totalvalue: '%%Amount%%',
};

The output for totalvalue contains a dollar sign, and I need to remove it. totalvalue的输出包含一个美元符号,我需要将其删除。

How can I do this with the example above? 如何使用上面的示例执行此操作?

UPDATE: 更新:

I think that Ian and abc123 most likely gave the correct answer to this. 我认为Ian和abc123最有可能对此给出正确的答案。 In my particular case, it was not providing the output that I wanted to see in the source code, so I created a new global variable and removed the dollar sign in php then and there. 在我的特定情况下,它没有提供我想在源代码中看到的输出,因此我创建了一个新的全局变量,然后在php中删除了美元符号。

This echoed it the way I wanted when using %%ModifiedAmount%%. 这与使用%% ModifiedAmount %%时我想要的方式相呼应。

You can call the replace function is JavaScript. 您可以调用的替换函数是JavaScript。

Original: 原版的:

var tag_params = {
    prodid: '',
    pagetype: 'cart',
    totalvalue: '%%Amount%%'.replace('$', ''),
};

Updated to use lan 's method: 更新为使用lan的方法:

< script type = "text/javascript" >
    var tag_params = {
        prodid: '',
        pagetype: 'cart',
        totalvalue: '%%Amount%%',
    };

    tag_params.totalValue = tag_params.totalValue.replace('$', ''); 
< /script>

tag_params.totalValue.replace('$','');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM