我是 jquery/ajax noob :)
我想出了这个:
$(function() {
$("#moreAdd").click(function() {
var dataString = [];
var selector = '#repeat0';
var row;
for(var i=0;$(selector).length != 0;i++){
row = [];
selector = '#repeat' + i;
row.push($(selector).val());
selector = '#distance' + i;
row.push($(selector).val());
selector = '#style' + i;
row.push($(selector).val());
selector = '#change' + i;
row.push($(selector).val());
selector = '#time' + i;
row.push($(selector).val());
dataString.push(row);
selector = '#repeat' + (i+1); //to check it's finished the for
}
$.ajax({
type: "POST",
url: "/index.php/trainings/showAdd",
data: dataString,
dataType: 'json',
success: function(data) {
$("div#addModalBody").html(data.html);
}
});
return false;
});
});
但我总是以一个空帖子结束。我认为选择器的东西不能正常工作我可以创建一个字符串然后使用该字符串按 id 选择吗?如果不是这样的话,如果有人能给我一个想法,我哪里错了..
谢谢,詹姆斯