欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

js動(dòng)態(tài)生成Html元素實(shí)現(xiàn)Post操作(createElement)

 更新時(shí)間:2015年09月14日 00:52:04   投稿:mdxy-dxy  
這篇文章主要介紹了js動(dòng)態(tài)生成Html元素實(shí)現(xiàn)Post操作(createElement),需要的朋友可以參考下

有時(shí),你需要Post數(shù)據(jù)到另一個(gè)頁面上,那么你就需要構(gòu)建一個(gè)Form表單

<form id="postform" name="postform" method="post">
<input name="msg" value=""/>
</form>

復(fù)制代碼 代碼如下:

document.write("<form ..."
//document.write("<iframe src=\"about:blank\" name=\"hiddenFrame\" id=\"hiddenFrame\" width=\"0\" height=\"0\" frameborder=\"0\"></iframe>");

用如下js提交不起作用,因?yàn)榇虻巾撁嫔系膄orm不是一個(gè)對(duì)象,而是一個(gè)字符串

//  theForm.action = "http://msg.baihe.com/tortoise/pages/tortoise/sm_gb2312.jsp?ReturnURL="+strReturnURL;
//  document.getElementById("Pathid").value="3070";
//  document.getElementById("Title").value="你好!";
//  document.getElementById("Content").value="我把你設(shè)為重點(diǎn)關(guān)注了,咱們聊聊吧:)";
//  document.getElementById("CloseWindow").value="1";

所以你需要自己動(dòng)態(tài)創(chuàng)建form對(duì)象,用如下方法實(shí)現(xiàn):

var form_feedback = document.createElement("form");
  document.body.appendChild(form_feedback);
    
  var i = document.createElement("input");
  i.type = "hidden";
  i.name = "Title";
  i.value = "你好!";
  form_feedback.appendChild(i);
  
  
  var j=document.createElement("input");
  j.type="hidden";
  j.name="Content";
  j.value="我把你設(shè)為重點(diǎn)關(guān)注了,咱們聊聊吧:)";
  form_feedback.appendChild(j);
  
  var hiddenIframe=document.createElement("iframe");
  hiddenIframe.src="about:blank";
  hiddenIframe.name="hiddenFrame";
  hiddenIframe.id="hiddenFrame";
  hiddenIframe.width="0";
  hiddenIframe.height="0";
  hiddenIframe.frameborder="0";
  form_feedback.appendChild(hiddenIframe);
  
  
  form_feedback.action = "http://msg.baihe.com/tortoise/pages/tortoise/sm_gb2312.jsp?ReturnURL=";
  form_feedback.target = "hiddenFrame";
  form_feedback.method = "post";
  form_feedback.submit();

相關(guān)文章

最新評(píng)論