如何仅使用原型在特定行之前追加 table 中的行
How to append row in table before specific row using prototype only
我正在尝试使用原型在 table 中追加行,但它总是会在 table 的末尾追加行 我怎样才能在特定行之后添加它 这是我的代码used to append row using template.I 想在 buttonsrow
id 之上追加行。此 ID 分配给特定行。
//<![CDATA[
var groupPriceRowTemplate = '<tr>'
+ '<td class="label"><input name="extraoption[]" value="" type="text" class="input-text"></td>'
+ '<td class="value"><input name="extravalues[]" value="" type="text" class="input-text"></td>'
+'<td class="value"><button title="Delete Group Price" type="button" class="scalable delete icon-btn delete-specification"><span>Delete</span></button></td>'
+ '</tr>';
var groupPriceControlspec = {
template: new Template(groupPriceRowTemplate, new RegExp('(^|.|\r|\n)({{\s*(\w+)\s*}})', '')),
addItem : function (event) {
console.log(Event.findElement(event, 'tr'));
Element.insert($('specification_container'), {
bottom : this.template.evaluate()
});
this.bindRemoveButtons();
},
deleteItem: function(event) {
var tr = Event.findElement(event, 'tr');
if (tr) {
Element.select(tr, ['td']).each(function(element) {
element.remove();
});
}
return false;
},
bindRemoveButtons : function(){
var buttons = $$('div.specification-container .delete-specification');
for(var i=0;i<buttons.length;i++){
if(!$(buttons[i]).binded){
$(buttons[i]).binded = true;
Event.observe(buttons[i], 'click', this.deleteItem.bind(this));
}
}
}
}
groupPriceControlspec.bindRemoveButtons();
if($('addnewspecrow')){
Event.observe('addnewspecrow', 'click', groupPriceControlspec.addItem.bind(groupPriceControlspec));
}
//]]>
其实应该很容易做到。
给定要放在 HTML 之前的元素的 id 是 buttonsrow
--
var content = "<tr><td></td></tr>";
$('buttonsrow').insert({'before':content});
我正在尝试使用原型在 table 中追加行,但它总是会在 table 的末尾追加行 我怎样才能在特定行之后添加它 这是我的代码used to append row using template.I 想在 buttonsrow
id 之上追加行。此 ID 分配给特定行。
//<![CDATA[
var groupPriceRowTemplate = '<tr>'
+ '<td class="label"><input name="extraoption[]" value="" type="text" class="input-text"></td>'
+ '<td class="value"><input name="extravalues[]" value="" type="text" class="input-text"></td>'
+'<td class="value"><button title="Delete Group Price" type="button" class="scalable delete icon-btn delete-specification"><span>Delete</span></button></td>'
+ '</tr>';
var groupPriceControlspec = {
template: new Template(groupPriceRowTemplate, new RegExp('(^|.|\r|\n)({{\s*(\w+)\s*}})', '')),
addItem : function (event) {
console.log(Event.findElement(event, 'tr'));
Element.insert($('specification_container'), {
bottom : this.template.evaluate()
});
this.bindRemoveButtons();
},
deleteItem: function(event) {
var tr = Event.findElement(event, 'tr');
if (tr) {
Element.select(tr, ['td']).each(function(element) {
element.remove();
});
}
return false;
},
bindRemoveButtons : function(){
var buttons = $$('div.specification-container .delete-specification');
for(var i=0;i<buttons.length;i++){
if(!$(buttons[i]).binded){
$(buttons[i]).binded = true;
Event.observe(buttons[i], 'click', this.deleteItem.bind(this));
}
}
}
}
groupPriceControlspec.bindRemoveButtons();
if($('addnewspecrow')){
Event.observe('addnewspecrow', 'click', groupPriceControlspec.addItem.bind(groupPriceControlspec));
}
//]]>
其实应该很容易做到。
给定要放在 HTML 之前的元素的 id 是 buttonsrow
--
var content = "<tr><td></td></tr>";
$('buttonsrow').insert({'before':content});