js_使用原生js方法提交post表单

   var url = "/ssm/role/setRoleModules.action";
   
   var postForm = document.createElement("form");//表单对象   
   postForm.method="post" ;   
   postForm.action = url;


   var roleidInput = document.createElement("input") ;   
   roleidInput.setAttribute("name", "setRoleId") ;   
   roleidInput.setAttribute("value", roleid);
   postForm.appendChild(roleidInput);  
    
   var moduleidsInput = document.createElement("input") ;   
   moduleidsInput.setAttribute("name", "RoleModuleIds") ;   
   moduleidsInput.setAttribute("value", RoleModuleIds);
   postForm.appendChild(moduleidsInput);       
    
   var timeInput = document.createElement("input") ; 
   timeInput.setAttribute("name", "time") ;   
   timeInput.setAttribute("value", Math.random());
   postForm.appendChild(timeInput);       
   
   document.body.appendChild(postForm) ;
   postForm.submit() ;   
   document.body.removeChild(postForm) ;  

 

 

你可能感兴趣的:(JS常用方法)