方法一:
formname.document.createElement("form");
document.body.appendChild(formname); //关键语句,否则submit()方法没有实际动作
//add other node
txtObj = document.createElement("input");
//1
txtObj.setAttribute("type","hidden");
txtObj.setAttribute("name","username");
txtObj.setAttribute("value","William");
formname.appendChild(txtObj);
//2
txtObj2 = document.createElement("input");
txtObj2.setAttribute("type","hidden");
txtObj2.setAttribute("name","actionTarget");
txtObj2.setAttribute("value","VacationSetting");
formname.appendChild(txtObj2);
formname.action = target;
formname.method="post";
formname.submit();
方法二:
var f = document.createElement(’form’);
document.body.appendChild(f); //关键语句,否则submit()方法没有实际动作
f.style.display = ‘none’; this.parentNode.appendChild(f);
var h = document.createElement(’input’);
h.type = ‘hidden’; h.name = ‘act’; h.value = ‘admin’;
f.appendChild(h);
var h2 = document.createElement(’input’);
h2.type = ‘hidden’; h2.name = ’setadmin’; h2.value = ‘delcat’;
f.appendChild(h2);
f.method = ‘POST’;
f.action = ‘index.php’;
f.submit();
return false
方法三:
function doIt()
{
formname = document.createElement("form");
document.body.appendChild(formname);
//add other node
txtObj = document.createElement("");
formname.appendChild(txtObj);
//2
txtObj2 = document.createElement("");
formname.appendChild(txtObj2);
//3
txtObj3 = document.createElement("");
formname.appendChild(txtObj3);
formname.action = target;
formname.method="POST";
formname.submit();
}