首页 > 解决方案 > 如何根据php中下拉框的选择来检索n个文本框上的数据

问题描述

当我从下拉框中选择1时,屏幕上会出现1个文本框,如果选择2,则会出现2个框等等。如果我在文本框中输入一些值,提交表单时无法检索这些值. 请提供从文本框中检索数据的代码。

标签: javascriptphp

解决方案


嗨,你可以做这样的事情

  <body>
    <div id="root">
      <button id="submit-button">get textarea data</button>
    </div>
  </body>
  <script>
    const rootEl = document.getElementById("root");
    const textareaEl = document.createElement("textarea");
    const buttonEl = document.getElementById("submit-button");

    buttonEl.addEventListener("click", retrieveTextareaData);
    rootEl.appendChild(textareaEl);
    rootEl.appendChild(submitButtonEl);

    function retrieveTextareaData(event) {
      event.preventDefault();
      const textAreaContent = textareaEl.value;

      console.log(textAreaContent);
    }
  </script>

推荐阅读