Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/88.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在javascript中访问输入的最佳方式是什么?_Javascript_Html_Input - Fatal编程技术网

在javascript中访问输入的最佳方式是什么?

在javascript中访问输入的最佳方式是什么?,javascript,html,input,Javascript,Html,Input,函数gener10k(){ 设x=getRndInteger(10000100); 设x1=getRndInteger(x,10); 设x2=x-x1; 设higherValue=numberToArray(x1); 常数长度=高值长度; 让higherInput=document.getElementsByName(“higher[]); 对于(var i=0;i

函数gener10k(){
设x=getRndInteger(10000100);
设x1=getRndInteger(x,10);
设x2=x-x1;
设higherValue=numberToArray(x1);
常数长度=高值长度;
让higherInput=document.getElementsByName(“higher[]);
对于(var i=0;iparseInt(x));
}

做吧
let higherInput=document.getElementsByName(“higer[]);
此语句获取一个对象

let higherValue=numberToArray(x1);
此语句获取一个数字数组

for
循环中:

higherInput[i].value=higherValue[i].value;
在此语句中,
higherInput[i].value
引用文本框值, 但是什么是高价值[i]。价值 只需使用
高值[i]

您可以使用下面的语句查看
higherValue[i]
是一个数字

console.log(typeof(higherValue[0]);

higherInput[i]
返回一个元素,而不是值higherValue不为值数组赋值….
console.log(higherInput[i].value,higherValue[i])
我如何访问值?它是有效的,谢谢。我只需要找出原因,但这对我来说是一个超级讲座。@user2062778我想你可能误解了value属性?你应该使用
value
来获取HTML对象,但不需要使用value来获取数值,number只是一个可以使用的值,它没有
value
属性,就像您定义的
x
一样,
x
是一个数字。是的,就是这个。我以前没有意识到它。