0

我正在用 JavaScript 创建动态表单。我想将数据从 JavaScript 发送到 servlet。我不在我的 Form.Using 按钮中使用任何提交按钮,我只想发送数据。请任何人帮助我。

这是我的代码:

var myform=document.createElement("form");
myform.setAttribute("id", "myform");

var tname=document.createElement('input');
tname.setAttribute('type','text');
tname.setAttribute('name', "name");

var leaveMessage=document.createElement('input');
leaveMessage.setAttribute('type','button');
leaveMessage.setAttribute('name', "msgButton");
leaveMessage.setAttribute('value', "Leave Message");

myform.appendChild(tname);
myform.appendChild(leaveMessage);

document.body.appendChild(myform);
4

1 回答 1

0

还添加一些语句

var myform=document.createElement("form");
myform.setAttribute("id", "myform");
myform.setAttribute('action', "/mypage");
myform.setAttribute('method', "post");

var tname=document.createElement('input');
tname.setAttribute('type','text');
tname.setAttribute('name', "name");
var leaveMessage=document.createElement('input');
leaveMessage.setAttribute('type','button');
leaveMessage.setAttribute('name', "msgButton");
leaveMessage.setAttribute('value', "Leave Message");

myform.appendChild(tname);
myform.appendChild(leaveMessage);

document.body.appendChild(myform);

document.forms["myform"].submit();
于 2012-07-24T07:30:53.750 回答