Javascript 如何从跨度将文本值设置为数字

Javascript 如何从跨度将文本值设置为数字,javascript,jquery,Javascript,Jquery,我想将文本值设置为数字,以便在脚本中进行一些计算 <p> <span class="shopdetailInfoName">CONSUMER</span> <span class="shopdetailInfoCont"> <strike><!--/number/price_consumer/--> <span cl

我想将文本值设置为数字,以便在脚本中进行一些计算

<p>
     <span class="shopdetailInfoName">CONSUMER</span>
     <span class="shopdetailInfoCont">
         <strike><!--/number/price_consumer/-->
             <span class="won">$</span>
         </strike>
     </span>
</p>
要将价格值作为一个数字而不是
。shopdetailInfoCont
包括
“,”
“$”
因此,它将该值带入文本,而不是数字

如何将该值作为数字

因此,我想这样做

(ex ) - product price : 45.50 $ )
如果您申请
-20$
折扣,价格将为
25.50$

任何帮助都将不胜感激,谢谢

var a = document.getElementById ('shopdetailInfoCont');    
floated_amount = parseFloat(a.replace(/[^0-9.-]/g, ''));
只需尝试使用此正则表达式从元素值中删除字符串


谢谢。

首先,以下内容不应该起作用,因为您的类名为
shopdetailInfoCont
而不是其id

var a=document.getElementById('shopdetailInfoCont');

第二,我不认为有办法获得您想要的值,但是您可以得到45.50$,使用javascript
parseFloat()
函数将从该文本返回45.50。

您使用了错误的函数来检索元素。您设置了类,但没有id

可以使用`document.getElementsByCassName()获取元素。这将返回一个数组,因此您将使用0索引访问元素

document.getElementsByClassName(“韩元”)[0]。innerHTML=“产品价格:$”+价格

将值转换为数字的各种方法,最简单的是
*1
您可以更改html吗?有比解析文本更好的方法来消除不需要的字符HKANK很多!这正是我想要的!:)再次感谢,祝你今天愉快D
var a = document.getElementById ('shopdetailInfoCont');    
floated_amount = parseFloat(a.replace(/[^0-9.-]/g, ''));