无需将表单写入新窗口(要用HTML代码中的值进行编码就很难正确地进行表单),只需打开一个空窗口并将表单发布到该窗口即可。
例:
<form id="TheForm" method="post" action="test.asp" target="TheWindow"><input type="hidden" name="something" value="something" /><input type="hidden" name="more" value="something" /><input type="hidden" name="other" value="something" /></form><script type="text/javascript">window.open('', 'TheWindow');document.getElementById('TheForm').submit();</script>编辑:
要动态设置表单中的值,可以执行以下操作:
function openWindowWithPost(something, additional, misc) { var f = document.getElementById('TheForm'); f.something.value = something; f.more.value = additional; f.other.value = misc; window.open('', 'TheWindow'); f.submit();}要发布表单,您可以使用值调用函数
openWindowWithPost('a','b','c');。注意:我改变了与表单名称相关的参数名称,以表明它们不必相同。通常,您将使它们彼此相似,以使其更易于跟踪值。



