Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2012/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何在php中根据下拉框的选择检索n个文本框上的数据_Javascript_Php - Fatal编程技术网

Javascript 如何在php中根据下拉框的选择检索n个文本框上的数据

Javascript 如何在php中根据下拉框的选择检索n个文本框上的数据,javascript,php,Javascript,Php,当我从下拉框中选择1时,屏幕上将显示1个文本框,如果选择2,则将显示2个框等。。如果在文本框中输入一些值,则在提交表单时无法检索这些值。请提供从文本框检索数据的代码 嗨,你可以这样做 <body> <div id="root"> <button id="submit-button">get textarea data</button> </div> </body> <script

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

嗨,你可以这样做

  <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>

获取文本区域数据
const rootEl=document.getElementById(“根”);
const textareaEl=document.createElement(“textarea”);
const buttonEl=document.getElementById(“提交按钮”);
Buttonnel.addEventListener(“单击”,检索ExtArea数据);
rootEl.appendChild(textareaEl);
附子根(submitButtonEl);
函数retrieveTextareaData(事件){
event.preventDefault();
const textAreaContent=textareaEl.value;
console.log(textAreaContent);
}