使用javascript创建和提交表单

我正在尝试创建一个表单并立即使用javascript提交它,我无法弄清楚我做错了什么。这是我的代码:

I'm trying to create a form and submit it immediately with javascript and I cannot figure out what I'm doing wrong. here is my code:

function autoLogIn(un, pw) {
var form = document.createElement("form");
document.body.appendChild(form);
form.method = "POST";
form.action = "login.php";
var element1 = document.createElement("<INPUT NAME='un' TYPE='hidden' VALUE='"+un+"'>");  
 form.appendChild(element1);
var element2 = document.createElement("<INPUT NAME='pw' TYPE='hidden' VALUE='"+pw+"'>"); 
form.appendChild(element2);
form.submit();
}




 1 条回答