【发布时间】:2020-05-15 06:20:02
【问题描述】:
我正在尝试编写一个代码,当我单击 DIV 时,复选框标记我,第二次单击时,它标记
颜色发生变化,DIV 发出咔哒声。但是自动选择和取消选中复选框不起作用
我有错误:
Uncaught TypeError: selectedValue.prop is not a function at HTMLDivElement.document.getElementById.onclick
我有带有此代码的 GSP 模板:
<div id="${item.key}">
<input id="Position_${item.key}" type="checkbox" /> ${index + 1}. ${item.key}
</div>
和脚本在同一个文件中:
<script>
document.getElementById('${item.key}').onclick = function () {
let selectedValue = document.getElementById('Position_${item.key}');
if (this.style.backgroundColor == 'lightgreen') {
changeColor(this, 'white');
selectedValue.prop('checked', false);
} else {
changeColor(this, 'lightgreen');
selectedValue.prop('checked', true);
}
};
</script>
【问题讨论】:
标签: javascript jquery html checkbox gsp