1
こんにちは私はconsole.log
をチェックしようとしています。チェックボックスがチェックされているかどうかをチェックします。返されないaddEventListenerは関数ではありません
var checkbox = document.querySelectorAll('.customer-club-widget__gender__categories .form__input-checkbox');
checkbox.addEventListener("change", function() {
var isChecked = checkbox.checked;
if(isChecked){ //checked
console.log('checked');
}else{ //unchecked
console.log('unchecked');
}
});
:
Uncaught TypeError:
checkbox.addEventListener is not a function
and a cant figure out why this is happening.
'querySelectorAll'アレイ.. – Keith
querSelectorAllの配列を返すを返します。配列をループしてすべての項目にリスナーを追加する必要があります。または、イベントの委任を使用してください。 –
'querySelectorAll'はNodeListを返します。ある時点でnodeListに含まれている各ノードにリスナーを追加する場合は、https://developer.mozilla.org/en-US/docs/Web/API/NodeList#Specifications – myf