javascript - 如何根据php中下拉框的选择来检索n个文本框上的数据
问题描述
当我从下拉框中选择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>
推荐阅读
- c# - 如何在 hostgator linux 共享主机上安装 ASP.NET Core 应用程序?
- r - R:逻辑回归,glm&predict:预测哪个类?
- c - x86-64 中的内存分配
- javascript - 如何添加 JS 脚本以在自定义共享点列表中创建“阅读更多”?
- javascript - 简单的 Ember.js `has-many` 关系不起作用
- python - 需要为 Python 3.7.2 IDLE 安装 pip 和 pygame(语法无效)
- c# - datagridview 日期排序 c#
- reactjs - React:如何在 API POST 后重新渲染组件以显示新数据?
- c# - 找不到作为项目一部分的自定义控件
- r - 在 R 中模拟肥尾数据