2014-01-08 99 views
0

我在网站上有此商业广告。在HTML标签中显示Javascript变量

http://img89.imageshack.us/img89/5157/mv8k.png(图片)。

这个商业包含价格的信息,这些价格是在JavaScript变量。我想在更新变量值时自动更新价格(价格介于红色字体的“Desde”和“Bs。”之间)。

HTML以显示这些标签有以下几种:

​​

价格以 “data.refPrice” 变量。我只想用类“printoriente-label-price”在标签中显示这些变量。我调查了一些关于“.each”和“.find”的javascript,我不知道它是否会成为解决方案。

我用它做了它,但它会与网站的其他部分产生冲突。我必须用其他方法去做,它让我想起了那样的事情。

问候。

+0

与ID冲突?只是使用唯一的ID,它应该没问题,我可以写你的例子,如果你想 –

+0

是的,但应该存在一种方式来做它取代“IDS”“类” – nandophillips

回答

0

这样做的最好方法是使用ID。它不应该与任何内容相冲突,只要你不使用同一个id两次。另一种方法是通过它的类调用元素,但那么你将不得不引用它的索引,如:

$.getJSON("http://api.printoriente.com/price/tarjetas-presentacion", function(data) { 
    $(document).find(".printoriente-label-price")[0].html(data.refPrice); 
}); 
$.getJSON("http://api.printoriente.com/price/afiches", function(data) { 
    $(document).find(".printoriente-label-price")[1].html(data.refPrice); 
}); 
$.getJSON("http://api.printoriente.com/price/volantes", function(data) { 
    $(document).find(".printoriente-label-price")[2].html(data.refPrice); 
}); 
$.getJSON("http://api.printoriente.com/price/Fotos", function(data) { 
    $(document).find(".printoriente-label-price")[3].html(data.refPrice); 
});