我已閱讀了多個主題,但沒有一個具體說明我的問題。我有一個表格作爲下拉菜單。 (是的,它必須是這樣)從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'。 –