我有一个小项目,其中我创建了基于用户输入的文本域。
$('#arraySizeButton').click(function() {
var arraySize = $("#arraySize").val();
if(arraySize=='') {
alert("Enter Some Text In Input Field");
}else{
var count = arraySize;
var html = [];
while(count--) {
html.push("\<input type='text' id='inputTextField", count, "'>");
}
$('#inputTextFieldsarea').append(html.join(''));
}
});我想创建一个基于上述代码的动态程序,并将数据从文本字段检索到数组中。感谢你的帮助。
发布于 2017-03-12 00:19:45
你是说这个吗?
html.push("<input type='text' id='inputTextField"+count+"'/>");发布于 2017-03-12 00:23:34
您应该做的是向输入的名称添加一个[],以便让html表单知道这是一个数组。
你应该这样做:
html.push("\<input name='field[]' type='text' id='inputTextField", count, "'>");使用php获取所有POSTed字段的内容,您可以简单地检查
字段$_POST“
”
这是一个数组。
编辑:如果你想像你在评论中所说的那样使用jquery来做这件事,那么你可以这样做:
$('[id^="inputTextField"]').each(function() {
alert($(this).val());
});https://stackoverflow.com/questions/42737504
复制相似问题