是否有这样的修改,可以使表单值出现

Is there a modification of this that can make the form value appear?

本文关键字:表单 可以使 修改 是否      更新时间:2023-09-26

这是表单

<form action="/missions/basic/3/index.php" method="post">
<input type="hidden" name="file" value="password.php" />
<input type="password" name="password" /><br /><br />
<input type="submit" value="submit" />
<input type=button value="Get Value" onclick="printIt()" /></form>

我这里有这些方法来尝试让值出现

function printIt(){
   for (i = 0; i < document.getElementsByName('password').length; i++) {
       var x = window.alert(document.getElementsByName('password')[i].value());
       window.alert(x);
   }
}

我想知道我可以在最后两个方法中做些什么来让值出现

函数document.getElementsByTagName()返回一个数组,而不是一个元素,因此将代码更改为window.alert(document.getElementsByName('password')[0].value);应该获得第一项的值。第一项很可能是表单中要查找的元素。