"我的问题"
我希望得到一些帮助,以了解如何访问input1和input2中的值,将它们存储在变量中,以便稍后可以将它们用于一个函数,该函数将计算这两个值并将其显示在结果div中。
const input1 = document.createElement("input");
document.body.appendChild(input1);
const input2 = document.createElement("input");
document.body.appendChild(input2);
const result = document.createElement("div");
document.body.appendChild(result);
2条答案
按热度按时间k97glaaz1#
一种方法是对创建的输入使用EventListener来操作数据
你也可以添加一个选择器(id或class)到创建的元素,并通过这个选择器恢复它
x一个一个一个一个x一个一个二个x
你的样本看起来像
一个三个三个一个
如果你必须动态创建div和showresult,你也可以创建按钮并操作onclick事件
j7dteeu82#
好的,这样Id就可以工作了,但是它只对那一行有效。我需要在每一个新创建的行上独立地重复这个过程(等式)。