Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/363.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 NextElementSibling不工作_Javascript_Html_Innerhtml_Html Input - Fatal编程技术网

JavaScript NextElementSibling不工作

JavaScript NextElementSibling不工作,javascript,html,innerhtml,html-input,Javascript,Html,Innerhtml,Html Input,我在元素内部有几个Javascript输入,在它们下面有一些Javascript输入 我还有一个javascript函数,如果有字母输入,它会清除输入值,这样它只接受数字 t=函数(elem){ 要素onkeyup=功能(e){ if(!/[\d\.]/.test(String.fromCharCode(e.which))){ 元素值=“”; x=elem.nextElementSibling; x、 innerHTML='无效字符串'; } }; }; 文本 文本 如您所见,如果您在任一输

我在元素内部有几个Javascript输入,在它们下面有一些Javascript输入

我还有一个javascript函数,如果有字母输入,它会清除输入值,这样它只接受数字

t=函数(elem){
要素onkeyup=功能(e){
if(!/[\d\.]/.test(String.fromCharCode(e.which))){
元素值=“”;
x=elem.nextElementSibling;
x、 innerHTML='无效字符串';
}
};
};

文本
文本

如您所见,如果您在任一输入中键入字母,它将清除该输入
您希望访问:
elem.parentNode.nextElementSibling
,因为您要查找的是
(父元素)的同级,而不是没有同级的

t=函数(elem){
要素onkeyup=功能(e){
if(!/[\d\.]/.test(String.fromCharCode(e.which))){
元素值=“”;
x=elem.parentNode.nextElementSibling;
x、 innerHTML='无效字符串';
}
};
};

文本
文本

nextElementSibling
指的是。。。下一个元素是兄弟。代码中的输入没有同级。您的输入没有同级,它们只是子项