我能够将341.376
的{{1}}评估为真,但不能为假。
它永远不会“点击否”
怎么回事?
https://jsfiddle.net/9wvp0ktd/
value
option
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');
}
}
};
答案 0 :(得分:1)
我很愚蠢,但value
数据类型为string
而不是bool
所以我改了
this.value
至this.value === 'true'