我使用的是jquery 1.6.4,我有一个表。最初在表中,用户只有一行和几列。然后,我允许用户通过这样做来添加他们想使用的任意多的行
$('.add').live('click', function(e){
e.preventDefault();
var $parentRow = $(this).parents('tr');
$parentRow.clone().insertAfter($parentRow);
$parentRow.next().find('input').val('');
$(this).replaceWith('<a href="#" class="delete">-</a>');
});我还允许他们在执行此操作时删除行
$('.delete').live('click', function(e){
alert("removing");
e.preventDefault();
$(this).parents('tr').remove();
});但是,现在我希望收集它们在这些列中输入的值。我不确定如何在单击提交按钮时收集这些值,因为在我的视图源代码中,我看到的只有以下内容
<tr>
<td class="actions"><a href="#" class="add">+</a></td>
<td><input type="text"></input></td>
<td><input type="text"></input></td>
<td><input type="text"></input></td>
<td><textarea rows="1"></textarea></td>
</tr>在页面源代码中,它只显示一行,而在我的视图中,我肯定看到添加了三行。不确定我遗漏了什么以及如何获取这些值
发布于 2012-01-25 08:42:36
您没有it,因此很难判断您实际收集的是什么,但是要获取输入的值,无论是静态的还是动态的,您可以使用以下命令:
//submit code
$('input[type=submit]').click(function(){
$('table input').each(function(index,item){
//for testing you could just output to a div
//$('#output').append($(this).val());
});
});发布于 2012-01-25 08:40:21
据我所知,您的输入字段没有名称,因此当按下submit时,您不会得到太多信息。
此外,您不会在视图源代码中看到DOM更新。查看源代码只会显示页面第一次加载时的外观。要获得页面的实时视图,您可以使用FireFox版的FireBug,或者如果您使用的是Google Chrome,在“视图”菜单下有一些开发人员工具,您可以使用这些工具来查看html的实时外观。
https://stackoverflow.com/questions/8996373
复制相似问题