我正在尝试传递凭据以自动填写此网站的输入登录名:https://www.pinterest.pt/login/ . 我不知道变量是什么。所以我使用浏览器的 inspect 来了解每个输入的 id 是什么。
我正在使用这段代码,但它不起作用:
function Test() {
var name = document.getElementById("id").value;
var password= document.getElementById("password").value;
document.forms["registerForm"].submit(); //form submission
}
<!DOCTYPE html>
<html>
<body>
<form id="registerForm" name="registerForm" method="post" target="_top" action="https://www.pinterest.pt/login/">
<input id="email" name="id" type="email" value="examplelogin" />
<input id="password" name="password" type="password" value="examplepassword" />
<input type="button" name="submit" id="btn" value="Submit" onclick="Test()" />
</form>
</body>
</html>
你知道我做错了什么吗?
感谢您的帮助。
最佳答案
与其说是您问题的答案,不如说是 future 的引用,您需要通过选择器获取表单中的所有元素。您可以简单地使用以下技术:
function Test() {
let form = document.getElementById('registerForm');
var password = form.elements.password.value;
var email = form.elements.email.value;
form.submit();
}
请注意访问 form.elements
如何授予对您尝试读出的 element
的直接访问权限。
关于javascript - 自动填写外部网页的特定登录表单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59627719/