我想通过JavaScript在一个特定的网页上自动提交(登录)表单(数据由浏览器重新编排)。 我设法提交非常容易使用这种测试形式,我在我的电脑上进行:JavaScript - 自动提交表单
document.forms["formID"].submit();
但是当我尝试在该网页上失败。我在Greasemonkey的页面上运行JavaScript,它工作正常,运行警报等,但提交不起作用。 网页是:http://plusklub.hteronet.ba/Login
我试着用的代码
document.addEventListener("DOMContentLoaded", function(event) {
document.forms["aspnetForm"].submit();
});
还使用得自顶部评论此代码对这个问题这部分W8负载Auto-Submit Form using JavaScript 失败意味着什么也没有发生。
有几件事情我想:
console.log("test1");
document.addEventListener("DOMContentLoaded", function(event) {
console.log("test2");
});
console.log("test3");
window.onload = function() {
console.log("test4");
}
}
console.log("test5");
var fo=document.getElementById("aspnetForm");
console.log(fo);
var bu=document.getElementsByClassName("button");
console.log(bu);
bu.click();
setTimeout(function(){ console.log("test6"); }, 3000);
输出如下因素:
test1helloworld.user.js:13:3
test3helloworld.user.js:17:3
test5helloworld.user.js:22:3
<form name="aspnetForm" method="post" action="/Login?ReturnUrl=http://plusklub.hteronet.ba/" id="aspnetForm">helloworld.user.js:24:3
HTMLCollection [ <input#ctl04_ctl02_btnSubmit.button> ]
当您运行代码时,您是否等待页面加载,因此表单存在?任何错误? “失败”具体是指什么? – charlietfl
@charlietfl,1st,你的时间。生病编辑我的问题 –
如果您在该事件处理程序中添加console.log()是否实际执行? –