【发布时间】:2016-03-08 16:14:23
【问题描述】:
我有两个数组:
var prices = [9.15, 10.10, 13.15, 4, 5, 6, 7, 8];
var premiumPrice = [9.15, 10.10, 13.15, 4, 5, 6, 7, 8];
加载 html 文档时,我需要将名为“prices”的数组中的数字插入到<div>,其中 id 对应于数组的索引,将“premiumPrice”插入另一个<div>。我认为 html 文档可能看起来像这样(注意 id 在哪里):
<div class="header" id="1">
<h2>BTC <span>1,00</span><em> /Month</em></h2>
<div class="price blue">SMALL</div>
</div><!--/ header -->
<div class="details">
<ul>
<li><b>1 000</b> sites</li>
</ul>
<div class="specialPromo">
<input type="checkbox"><label>Add <b>PREMIUM</b><br><em>(+<span id="1">0,15</span> usd/month)</em></label>
</div><!--/ specialPromo -->
</div><!--/ details -->
<a href="/cos/cos/ID" class="btn ">SELECT</a>
</div><!--/ item -->
按下复选框后div header必须返回premiumPrice+price(来自数组)。
我不知道如何做这份工作。
【问题讨论】:
-
请将您的 实际 HTML 复制到问题中,而不是它的屏幕截图,以及您为解决问题而编写的 JS 代码。
-
@Roy 目前,我通过使用从 html 文件中获取数字的正则表达式解决了这个问题(在从底部(输入)粘贴 5 行和从顶部粘贴 2 的代码中)。单击按钮(btn 类)后,从 html 中获取数字,将它们添加并扔到第 2 行(在上面的示例中)
标签: javascript jquery html arrays