/sf/ask/17360801/向您展示如何通过邮件提交您通过JavaScript创建的表单.以下是我修改过的代码.
var form = document.createElement("form"); form.setAttribute("method", "post"); form.setAttribute("action", "test.jsp"); var hiddenField = document.createElement("input"); hiddenField.setAttribute("name", "id"); hiddenField.setAttribute("value", "bob"); form.appendChild(hiddenField); document.body.appendChild(form); // Not entirely sure if this is necessary form.submit();
我想做的是在新窗口中打开结果.我当前正在使用这样的东西在新窗口中打开一个页面:
onclick = window.open(test.html, '', 'scrollbars=no,menubar=no,height=600,);
liggett78.. 219
加
要么
form.setAttribute("target", "_blank");
到你的表格的定义.
加
要么
form.setAttribute("target", "_blank");
到你的表格的定义.
如果你想从你的问题中创建和提交你的表单,你想要创建具有自定义功能的弹出窗口我建议这个解决方案(我把评论放在我添加的行之上):
var form = document.createElement("form"); form.setAttribute("method", "post"); form.setAttribute("action", "test.jsp"); // setting form target to a window named 'formresult' form.setAttribute("target", "formresult"); var hiddenField = document.createElement("input"); hiddenField.setAttribute("name", "id"); hiddenField.setAttribute("value", "bob"); form.appendChild(hiddenField); document.body.appendChild(form); // creating the 'formresult' window with custom features prior to submitting the form window.open('test.html', 'formresult', 'scrollbars=no,menubar=no,height=600,); form.submit();
var urlAction = 'whatever.php'; var data = {param1:'value1'}; var $form = $('