【发布时间】:2017-07-06 21:09:27
【问题描述】:
我可以创建一个带有增量器和减量器选项的 onlick 动态按钮,但我无法为其他按钮创建动态 id,因为这些按钮不会增加或减少。目前,即使单击其他按钮,也只有第一个按钮会减少/增加。
当您单击+ 图标内容时,会在“管理投资组合”部分添加一个增量器/减量器按钮。我尝试了 Stack Overflow 上定义的不同解决方案,但它们似乎在这里不起作用。
<table>
<thead>
<tr>
<th>STOCK</th>
<th>PRICE</th>
<th>SHARES</th>
<th>WEIGHT</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="stock in stocksArray" class="portfoliokey">
<td>{{stock.key}}</td>
<td class="portfoliovalue">{{"₹" + stock.value}}</td>
<td>
<input type="button" onclick="decrementValue()" value="-">
<input type="button" id="number" value="0" />
<input type="button" onclick="incrementValue()" value="+" />
</td>
<td></td>
</tr>
</tbody>
</table>
脚本
function incrementValue() {
var value = parseInt(document.getElementById('number').value, 10);
value = isNaN(value) ? 0 : value;
value++;
document.getElementById('number').value = value;
}
function decrementValue() {
value = parseInt(document.getElementById('number').value, 10);
value = isNaN(value) ? 0 : value;
value--;
document.getElementById('number').value = value;
}
【问题讨论】:
标签: javascript jquery angularjs