Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/462.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_Button_Types_Onclick - Fatal编程技术网

Javascript 无法读取未定义的正确长度?

Javascript 无法读取未定义的正确长度?,javascript,button,types,onclick,Javascript,Button,Types,Onclick,我创建了一个函数,它接受我在html文本框中编写的字符串,并在下一个文本框中打印该字符串的长度(第一个文本框是我html页面上的第五个文本框) 然后,我使用onClick方法通过调用函数在第6个文本框中打印字符串的长度 <label><input type="button" value="Trouve" onClick="LongueurChaine()"/></label> Uncaught TypeError: Cannot read property

我创建了一个函数,它接受我在html文本框中编写的字符串,并在下一个文本框中打印该字符串的长度(第一个文本框是我html页面上的第五个文本框)

然后,我使用onClick方法通过调用函数在第6个文本框中打印字符串的长度

<label><input type="button" value="Trouve" onClick="LongueurChaine()"/></label>

Uncaught TypeError: Cannot read property 'length' of undefined
at LongueurChaine (demo.js:54)
at HTMLInputElement.onclick (gabarit.html:85)
LongueurChaine @ demo.js:54
onclick @ gabarit.html:85

未捕获的TypeError:无法读取未定义的属性“length”
在隆古尔切恩(demo.js:54)
在HTMLInputElement.onclick(gabarit.html:85)
LongueurChaine@demo.js:54
onclick@gabarit.html:85

每次我试着点击按钮时,我都会得到这个结果。。?有没有更简单的方法来实现这一点?

如果它是第5个文本框,那么它在结果数组中的索引必须是4

另外,您的选择器是[text='text'],我猜您的意思是[type='text']

function StringLength(){    
   var aInput = document.querySelectorAll("[type='text']");
   var sResult = aInput[4].length;
   aInput[5].value = (sResult);    
}

字符串:
长度:
“x”:
“x”的位置:
整数:
烧焦:
提取:


您应该为所询问的语言添加标记。看起来您正在询问JavaScript,但请给大家一些帮助!(你也会更容易找到合适的人。)还是同样的错误吗?你能为文本框提供一些代码吗?这是我的文本框第二部分的HTML代码,是的,仍然是相同的错误。
function StringLength(){    
   var aInput = document.querySelectorAll("[type='text']");
   var sResult = aInput[4].length;
   aInput[5].value = (sResult);    
}
                <div> 
                <fieldset>
                    <label>String : <input type="text" name="Nom"/></label>

                    <label>Length : <input type="text" name="Nom"/></label>

                    <label>'x' : <input type="text" name="Nom"/></label>

                    <label>Position of 'x' : <input type="text" name="Nom"/></label>

                    <label>Integer : <input type="text" name="Nom"/></label>

                    <label>char : <input type="text" name="Nom"/></label>

                    <label>Extraction : <input type="text" name="Nom"/></label>


                </fieldset>

                      <fieldset>

                    <label><input type="reset" value="Efface"/></label> 
                          <br>
                    <label><input type="button" value="Trouve" onClick="StringLength()"/></label> 


                     </fieldset>
                </div