ITeye博客

js 实现post方式传递

foolraty · 2010-04-27 15:14 · Web前端 · Markdown

数组 语法 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>

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。