zoukankan      html  css  js  c++  java
  • 动态生成Html元素实现Post操作(createElement)


    有时,你需要Post数据到另一个页面上,那么你就需要构建一个Form表单
    <form id="postform" name="postform" method="post">

    <input name="msg" value=""/>
    </form>

    但如果当前页面是用js打到页面上的,那么你在用js提交时不起作用
    document.write("<form ..."
    //document.write("<iframe src=\"about:blank\" name=\"hiddenFrame\" id=\"hiddenFrame\" width=\"0\" height=\"0\" frameborder=\"0\"></iframe>");

    用如下js提交不起作用,因为打到页面上的form不是一个对象,而是一个字符串
    //    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="我把你设为重点关注了,咱们聊聊吧:)";
    //
        document.getElementById("CloseWindow").value="1";


    所以你需要自己动态创建form对象,用如下方法实现:
    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
    ="我把你设为重点关注了,咱们聊聊吧:)";
        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();

  • 相关阅读:
    Ubuntu Linux Matlab 安装 中文乱码 桌面启动器 Could not find the main class: java/splash.png. 终端terminal 直接运行 matlab
    Ubuntu Linux 官网 u盘安装 u盘系统 图文教程
    从google map google earth获得大图 方法总结
    论文查重网址
    [ZZ] Computer Science Conference Rankings
    Ubuntu linux 信使 iptux Window 飞鸽 ipmsg 飞秋 feiq 文件传输
    Ubuntu Linux Matlab mex
    Ubuntu Dell OptiPlex 990 Intel Gigabit CT Desktop Adapter网卡驱动安装
    C++的File类文件操作
    GIS软件比较
  • 原文地址:https://www.cnblogs.com/goody9807/p/900315.html
Copyright © 2011-2022 走看看