js 兑现post方式传递

js 实现post方式传递
数组 语法 var in
<script language="javascript">
function postwith (to,p) {
  var myForm = document.createElement("form");
  myForm.method="post" ;
  myForm.action = to ;
  for (var k in p) {
    var myInput = document.createElement("input") ;
    myInput.setAttribute("name", k) ;
    myInput.setAttribute("value", p[k]);
    myForm.appendChild(myInput) ;
  }
  document.body.appendChild(myForm) ;
  myForm.submit() ;
  document.body.removeChild(myForm) ;
}
</script>


To insert a link into a page just use a normal anchor tag in the HTML and call the function.
<a href="javascript:postwith('post.aspx',{user:'peter',cc:'aus'})">click</a>