【发布时间】:2011-02-08 21:15:03
【问题描述】:
我遇到过的最奇怪的错误。开个玩笑,但它肯定在顶部。
如果我像这样创建了一个动态表单..
= form_tag main_index_path, :method => :post do
.payment
= text_field_tag "payments[0][:date_paid]"
= text_field_tag "payments[0][:amount_paid]"
%br/
= link_to 'Add Another Payment', '#', :class => "add_another"
.actions
%br/
= submit_tag 'calculate'
然后点击'Add Another Payment'
一个新的 .payment div 将如下所示:
.payment
= text_field_tag "payments[1][:date_paid]"
= text_field_tag "payments[1][:amount_paid]"
奇怪的是,它仅在 IE6 和 IE7 中,它只会通过 first 和 last 付款。
如何/为什么/我可以做些什么来解决这个问题?
作为参考,这里是 'add_another' 方法:
$(".add_another").click(function(){
if ($(".payment:last").find("input").val() != "") {
var $newdiv = $(".payment:last").clone(true);
$newdiv.find('input').each(function() {
var $this = $(this);
$this.attr('id', $this.attr('id').replace(/_(\d+)_/, function($0, $1) {
return '_' + (+$1 + 1) + '_';
}));
$this.attr('name', $this.attr('name').replace(/\[(\d+)\]/, function($0, $1) {
return '[' + (+$1 + 1) + ']';
}));
$this.val('');
});
$newdiv.find('textarea').each(function(){
var $this = $(this);
$this.attr('id', $this.attr('id').replace(/_(\d+)_/, function($0, $1) {
return '_' + (+$1 + 1) + '_';
}));
$this.attr('name', $this.attr('name').replace(/\[(\d+)\]/, function($0, $1) {
return '[' + (+$1 + 1) + ']';
}));
$this.css("color","#cccccc");
});
$newdiv.insertAfter('.payment:last').hide().slideDown();
};
return false;
});
【问题讨论】:
-
我建议您只需使用当前时间(以毫秒为单位)作为新付款的 id,您会确保它是唯一的。
-
您认为这就是它无法通过参数的原因吗?在检查参数时,只有第一个和最后一个通过。
-
我不认为这是相关的,我应该更清楚一点,只是为了节省一些代码。
标签: jquery html ruby-on-rails internet-explorer params