我已阅读了多个主题,但没有一个具体说明我的问题。我有一个表格作为下拉菜单。 (是的,它必须是这样)从javascript的下拉列表中获取多个值
var blocka = "test1"
$('#john').on('change', function() {
if (this.checked) {
this.setAttribute("checked", "checked");
this.checked = true;
}
if (this.checked) {
//checkbox clicked is now checked
var tx = document.getElementById('james').innerHTML;
$('.variant_title').text(tx);
}
if (this.checked) {
//checkbox clicked is now checked
var rx = document.getElementById('matt').innerhtml;
$('.variant_price').text(rx);
} else {
this.setAttribute("checked", ""); // For IE
this.removeAttribute("checked"); // For other browsers
this.checked = false;
$('.variant_title').empty();
$('.variant_price').empty();
}
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table class="special-select">
<tbody>
<tr>
<td>
<span class="selecter-selected variant_title" name="click_me" style="height:40px! important;"></span>
</td>
</tr>
<tr id="picker" class="select-closed" style="font-size:.75rem;float:left!
important;min-height:1.20em;">
<td><input id="john" name="updates[31435395282]" type="checkbox" value="31435395282:" /> </td>
<td>MAPerformance Hoodie - Unisex Hoodie/Black/S - <span id="matt">$0.01</span></td>
<td id="james" class="hide">Unisex Hoodie/Black/S - $0.01</td>
</tr>
<tr id="picker" class="select-closed" style="font-size:.75rem;float:left!
important;min-height:1.20em;">
<td><input id="john" name="updates[31435395346]" type="checkbox" value="31435395282:" /> </td>
<td>MAPerformance Hoodie - Unisex Hoodie/Black/M - <span id="matt">$0.01</span></td>
<td id="james" class="hide">Unisex Hoodie/Black/M - $0.01</td>
</tr>
<tr id="picker" class="select-closed" style="font-size:.75rem;float:left!
important;min-height:1.20em;">
<td><input id="john" name="updates[31435395410]" type="checkbox" value="31435395282:" /> </td>
<td>MAPerformance Hoodie - Unisex Hoodie/Black/L - <span id="matt">$0.01</span></td>
<td id="james" class="hide">Unisex Hoodie/Black/L - $0.01</td>
</tr>
</tbody>
<div class="variant_price"></div>
</table>
我使用得到“詹姆斯”的值的代码工作的第一个复选框输入。但是,当我取消选中输入并尝试检查新输入时,我没有看到variant_title的值。
我该如何让它比第一次迭代更有效?
后返回的HTML,而不是预先渲染,这并不帮助我们来帮助你。 – Cam
我为@Cam添加了值 – JCQ50
这不是解决您的问题的方法,而是'innerhtml'≠'innerHTML'。 –