Javascript 从输入单选按钮获取值时出错
Javascript 从输入单选按钮获取值时出错,javascript,dom,firebase-realtime-database,null,typeerror,Javascript,Dom,Firebase Realtime Database,Null,Typeerror,var numb=0; var-responsen=[]; uid=123; 函数提交(){ 对于(var index=0;index我认为问题在于元素的名称。您只使用数字。根据,id或名称字段上至少应有on个字符。此外,您尝试使用选择器\1,它是id选择器。您的名称选择器应如下所示 document.querySelector('[name="yourElemeName"]') 您需要在querySelector中使用id或类名。 若您希望使用类,它应该类似于docume
var numb=0;
var-responsen=[];
uid=123;
函数提交(){
对于(var index=0;index我认为问题在于元素的名称。您只使用数字。根据,id或名称字段上至少应有on个字符。此外,您尝试使用选择器\1
,它是id选择器。您的名称选择器应如下所示
document.querySelector('[name="yourElemeName"]')
您需要在querySelector中使用id或类名。
若您希望使用类,它应该类似于document.querySelector('.classname')
如果您想使用Id,那么document.querySelector(“#IdofElement”)最终解决了这个问题
for (var index = 0;index<numb; index++){
var form = document.getElementById("value");
const forms = document.forms.value;
var name=index+1;
const radios = forms.elements[name.toString()].checked;
const query='['+'name="'+name+'"]'
var radval=document.querySelector('input'+query+':checked');
var radval1=document.querySelector('input'+query+':checked');
//var val1=form.getElementById(name).value;
**if (radval1!=null) {
responsen.push(radval.value)
}
else{
responsen.push("")
}
console.log(radval,radios)
console.log(responsen)
}**
for(var index=0;indexpress)请检查变量查询值是否正确。它应该指向所需值的正确元素。现在,我已经解决了这个问题,我认为将其命名为数字非常合适。