如果添加的任何文本输入/框为空,则页面不得提交。当我尝试使用文本输入的 id 检索值时,没有检索到任何内容是否可以从动态添加的元素中检索值?
$("#submit").click(function (event) {
var string = "tb";
var i;
for (i = 1; i <= count; i++) {
if (document.getElementById(string+1).value=="") {
event.preventDefault();
break;
}
}
});
上面的代码是我使用id从文本字段获取值的代码
最佳答案
我查看了 JSFiddle 中的代码。看来输入文本框没有给出预期的 ID; ID 被赋予容器 div。
添加按钮的代码应该使用这个,
var inputBox = $('<input type="text" id="td1">') //add also the needed attributes
$(containerDiv).append(inputBox);
关于javascript - 从动态添加的元素中获取值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23910565/