javascript - 我需要向 javascript 中创建的输入发送一些文本
问题描述
我用 javascript 生成了一个表,用于在您需要时添加行(它是一个订单),对于产品输入,我需要从数据库中获取详细信息。为了做到这一点,我现在正在尝试在 javascript 中使用一个非常简单的弹出窗口,并使用一个函数来捕获我需要填写的输入的 id(显然,每一行和每个字段都有自己的 id)。我附上了我现在正在尝试的示例代码,我总是遇到同样的问题,我找不到用于放置文本的输入 ID。
这是生成提示的函数,我没有更改任何内容,仅用于尝试是否可以将文本发送到我的输入:
function PopupProd(n) {
var txt;
var person = prompt("Please enter your name:", "Maria");
if (person == null || person == "") {
txt = "User cancelled the prompt.";
} else {
txt = "Hello " + person + "! How are you today?";
}
//here is my problem, I tried with innerHTML too, and in many ways for find the id input
document.getElementById('n').value = txt;
}
这是我生成用于显示提示的按钮的字段,与“n”输入在同一行中:
if (c == 2) {
var popeleProd = document.createElement('input');
// set the attributes.
popeleProd.setAttribute('type', 'button');
popeleProd.setAttribute('value', 'Producto');
// add button's "onclick" event.
//numline is the variable that contains the number of row that I am looking for
//it works
popeleProd.setAttribute('onclick', 'PopupProd(idProd' + numline + ')');
td.appendChild(popeleProd);
}
我是javascript的新手,我认为问题是因为我生成了表格,而javascript找不到必须在哪里放置文本,请你帮帮我吗?如果您需要更多代码来理解,我现在不需要。我不得不说我尝试了很多方法,我总是遇到同样的问题,我可以看到我找到了id,但我无法将文本发送给它。
谢谢!!
解决方案
对不起,我删除了这个问题,我认为任何人都看不到它。谢谢!!
推荐阅读
- sql - 如何将 CTE 更改为视图
- flutter - JSON/数据表:未来
不是类型的子类型 - python - Python 中的嵌套列表:初始化和预期值问题
- json - 如何使用 Angular 中的 http 客户端和 Observables 遍历 JSON 对象数组
- authentication - 如何在 Jwt 模式下的 AdonisJs 中验证没有密码的用户?
- c - 如何识别静态变量的范围?
- r - JSS文章模板中的多个从属关系
- python - 使用 BeautifulSoup 抓取具有相同类名的多个数据
- python - 基于匹配列 pandas 组合行
- jquery - 将关闭按钮添加到使用 jquery 创建的查看器中?