我发现了一个jQuery脚本来创建一个表,并有一个按钮来添加行到表的底部。然后点击每行时有链接删除该特定行。 Chrome & Safari中的所有功能都可以正常使用,但FireFox或IE中无法使用。这里是Jquery。。删除工作在铬和Safari浏览器,但不是在FF和IE
if ($("table#data tbody tr").size() == 1) {
$('.deleteRowButton').hide();
}
$('.deleteRowButton').live('click',function() {
var bid = $(this).attr('id');
var nid = bid.replace(/[^\d.]/g, "");
var pid = $("#product" + nid).val();
$("#productschanges").append("2:" + nid + ":" + pid + ",");
if ($("table#data tr").size() > 1) {
$(this).parents('tr').first().remove();
if ($("table#data tbody tr").size() == 1) {
$('.deleteRowButton').hide();
} else {
$('.deleteRowButton').show();
}
} else {
$('.deleteRowButton').hide();
}
});
$(".addRowButton").click(function() {
$("table#data tbody tr:last").clone(true).find("select").each(function() {
$(this).attr({
'id': function(_, id) {
return this.id.replace(/[0-9]/g, '') + i;
},
'name': function(_, name) {
return this.name.replace(/[0-9]/g, '') + i;
},
'value': function(_, value) {
return '';
}
});
$(this).prop('disabled', false);
}).end().find("input").each(function() {
$(this).attr({
'id': function(_, id) {
return this.id.replace(/[0-9]/g, '') + i;
},
'name': function(_, name) {
return this.name.replace(/[0-9]/g, '') + i;
},
'value': function(_, value) {
return '';
}
});
}).end().find("button").each(function() {
$(this).attr({
'id': function(_, id) {
return this.id.replace(/[0-9]/g, '') + i;
},
});
}).end().appendTo("table#data tbody");
i++;
$('.deleteRowButton').show();
});
.deleteRowButton中的append适用于所有浏览器,但不会按预期删除该行。任何帮助,为什么这不是在两个浏览器中工作?
感谢 2Pher
您是否在IE或FF控制台中看到任何javascipt错误? – SRy 2013-02-23 08:33:52
你可以做小提琴吗? – Barmar 2013-02-23 08:38:38
我没有看到任何错误。我试图做一个小提琴,但我甚至无法让添加行在小提琴中工作。这里是我创建的测试页面的链接,如果您使用chrome或safari添加配料和去除配料工作。然而,在Firefox(我相信IE,我没有它测试),删除成分按钮不起作用。 http://skafreaksonline.com/test.php?func=edit&editid=5 – 2013-02-23 09:29:31