测试用户是否单击true或false

时间:2017-10-22 08:29:03

标签: javascript html

我能够将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');
        }
    }
};

1 个答案:

答案 0 :(得分:1)

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

this.valuethis.value === 'true'