日期:2014-05-16 浏览次数:20336 次
<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> </head> <body> <div id="formID"></div> <script type="text/javascript"> function formAction(){ var formElement = document.createElement('form'); formElement.setAttribute('id','form1'); formElement.setAttribute('name','form1'); formElement.setAttribute('action','a.php'); formElement.setAttribute('method','get'); var inputTextElement = document.createElement('input'); inputTextElement.setAttribute('id','txt_name'); inputTextElement.setAttribute('type','text'); inputTextElement.setAttribute('value','aa'); var inputButtonElement = document.createElement('input'); inputButtonElement.setAttribute('id','btnSubmit'); inputButtonElement.setAttribute('type','button'); inputButtonElement.setAttribute('value','确定'); inputButtonElement.setAttribute('onclick',fnBtn); formElement.appendChild(inputTextElement); formElement.appendChild(inputButtonElement); var objForm = document.getElementById('formID'); objForm.appendChild(formElement); } formAction(); function fnBtn(){ return document.form1.submit(); } if(window.attachEvent){ window.attachEvent('onclick',fnBtn); }else if(window.addEventListener){ window.addEventListener('click',fnBtn,true); } </script> </body> </html>
------解决方案--------------------
$(function(){
var t_form = $("<form name='form1'></form>");
$("body").append(t_form);
$("form[name='form1']").submit();
});