首页 > 解决方案 > 使用 JavaScript 将另一个 HTML 文件形式的数据写入一个 HTML 文件

问题描述

我有两个文件:upload.htmldata.html

upload.html有这种形式:

<form class="subir_py" type="POST">
    <div class="row">
    <div class="col-md-12">
        <div class="titlepage">
        <h2>Datos</h2>
        </div>
        <div class="col-md-12">
        <input
            class="contactus"
            placeholder="Name"
            type="text"
            id="name"
            required
        />
        </div>                 
        <div class="col-md-12">
        <textarea
            class="textarea"
            placeholder="Description"
            type="text"
            name="Message"
            id="message"
        ></textarea>
        </div>
        <div>
        <input
            class="imagearea"
            type="hidden"
            name="MAX_FILE_SIZE"
            value="4194304"
        />
        <input type="file" />
        </div>
        <div class="col-xl-12 col-lg-12 col-md-12 col-sm-12">
        <button
            id="btnUpload"
            class="btnUpload"
            type="button"
            onclick="getData()"
        >
            Subir
        </button>
        </div>
    </div>
    </div>
</form>

如您所见,我有一些数据要在那里收集和一张图像。现在,我想在 data.html 中以 id 为“proyects”的 div 中写入以这种形式收集的数据

所以,我创建了app.js

function getData() { 
  const nombreProyecto = document.getElementById("name").value;
  const nombreOrganizacion = document.getElementById("message").value;
}

function writeData() {
  var newDivName = document.createElement("div");
  newDivName.appendChild(document.createTextNode(proyectName));
  document.getElementById("proyects").appendChild(proyectName);
}

问题是因为它们是不同的 html 文件,所以在文件中找不到名为“proyects”的 div data.html。我尝试过使用 webpack,但是由于我已经完成了所有的 html 和 css,所以现在很难捆绑所有内容。有谁知道另一种解决方案?

谢谢!

标签: javascripthtmlforms

解决方案


推荐阅读