如何使用JavaScript来乘以id内部id? [英] How to multiply span inner by id using JavaScript?

查看:103
本文介绍了如何使用JavaScript来乘以id内部id?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个显示货币的跨度。
这是我的跨度:

 < span id =v3_40>< / span> 

它只会显示通过浏览器加载的货币,并且需要脚本显示结果:

 < script src =// service.arzlive.com/p.js\"> ;</脚本> 

它显示了一个像这样的货币编号:38,355

我怎样才能从这个跨度中提取出这个数字,并将其乘以另一个数字,并将其显示为另一个跨度中的结果?
我需要一个代码来获取跨度数值

解决方案

您可以使用 innerHTML 来获取并设置您的 span 值。

  document.getElementById('new')。innerHTML = document.getElementById('v3_40')。innerHTML * 12;  

< span id =v3_40> 38.355< / span> * 12 =< span id =new>< / span>



在看到对这个答案的评论后,这里有一个更详细的方法;

  var originalPrice = document.getElementById('v3_40')。innerHTML; 
var price = originalPrice.replace(/ \,/ g,'');
var newPrice = parseFloat(price,20)* 12;
newPrice = newPrice.toLocaleString();

document.getElementById('new')。textContent = newPrice;

希望有帮助!


I have a span which shows a currency. This is my span:

<span id="v3_40"></span>

It will only show the currency when it's being loaded through a browser and it needs the script bellow to show the result:

<script src="//service.arzlive.com/p.js"></script>

It shows a currency number like this: 38,355

How can i extract this number out from this span and multiply it by another number and show it as the result in another span? I need a code to get the numeric value out from the span

解决方案

You can use innerHTML to get and set your span values.

document.getElementById('new').innerHTML = document.getElementById('v3_40').innerHTML * 12;

<span id="v3_40">38.355</span>
* 12 = 
<span id="new"></span>

EDIT:

After seeing the comments to this answer, here's a more detailed approach;

var originalPrice = document.getElementById('v3_40').innerHTML;
var price = originalPrice.replace(/\,/g,'');
var newPrice = parseFloat(price,20) * 12;
newPrice = newPrice.toLocaleString();

document.getElementById('new').textContent = newPrice;

Hope that helps!

这篇关于如何使用JavaScript来乘以id内部id?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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