gpt4 book ai didi

javascript - 测试用户点击 true 还是 false

转载 作者:行者123 更新时间:2023-12-03 03:13:18 25 4
gpt4 key购买 nike

我能够将选项评估为真,但不能评估为假。它永远不会“点击否”

怎么会这样?

https://jsfiddle.net/9wvp0ktd/

const versionNum = document.querySelector('#version-num');
const jarName = document.querySelector('#jar-name');
const getLatest = document.querySelector('#get-latest-yn');
getLatest.onclick = function () {
if (this.value === 'none') {
console.log('clicked none');
if (!versionNum.classList.contains('hidden')) versionNum.classList.add('hidden');
if (!jarName.classList.contains('hidden')) jarName.classList.add('hidden')
} else {
if (this.value) {
console.log('clicked yes');
if (versionNum.classList.contains('hidden')) versionNum.classList.remove('hidden');
if (!jarName.classList.contains('hidden')) jarName.classList.add('hidden');
} else{
console.log('clicked no');
if (!versionNum.classList.contains('hidden')) versionNum.classList.add('hidden');
if (jarName.classList.contains('hidden')) jarName.classList.remove('hidden');
}
}
};
.hidden{
display: none;
}
<div>
<label class="desc" for="get-latest-yn">Latest Binary?</label>
<div>
<select id="get-latest-yn" name="get-latest-yn" class="field select medium" tabindex="1">
<option value="none"></option>
<option value="true">Yes</option>
<option value="false">No</option>
</select>
</div>
</div>
<div id="version-num" class="hidden">
clicked yes
</div>

<div id="jar-name" class="hidden">
clicked no
</div>

最佳答案

好吧,我很愚蠢,但是value数据类型是string而不是bool,所以我改变了

this.valuethis.value === 'true'

关于javascript - 测试用户点击 true 还是 false,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46872024/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com