如何使用克隆jQuery脚本添加/删除行?
AddButton(克隆)代码:如何使用克隆jQuery脚本添加/删除行?,jquery,clone,Jquery,Clone,AddButton(克隆)代码: $.fn.btnAddRow=$.fn.tableAutoAddRow=函数(选项,函数){ var回调; 如果(选项类型==“对象”) 回调=(func&&$.isFunction(func))?func:null; 其他的 回调=(选项&&$.isFunction(选项))?选项:null; 选项=$。扩展({ maxRow:null, ignoreClass:null, rowNumColumn:null, autoAddRow:false, oddRow
$.fn.btnAddRow=$.fn.tableAutoAddRow=函数(选项,函数){
var回调;
如果(选项类型==“对象”)
回调=(func&&$.isFunction(func))?func:null;
其他的
回调=(选项&&$.isFunction(选项))?选项:null;
选项=$。扩展({
maxRow:null,
ignoreClass:null,
rowNumColumn:null,
autoAddRow:false,
oddRowCSS:null,
evenRowCSS:null,
inputBoxAutoNumber:false,
inputBoxAutoId:false,
displayRowCountTo:null,
maxRowAttr:null,
hideFirstOnly:null,
showFirstOnly:null,
cloneClass:null,
evenRowAttr:null,
oddRowAttr:null,
rowCountAttr:null,
autoNumAttr:null,
autoIdAttr:空
},选项);
这个。每个(函数(){
变量tbl、etbl、cloneClass;
if(typeof options.cloneClass==“string”&&options.cloneClass!=”){
if($(this).closest(“table”).find(“.”+options.cloneClass).size()>0){
tbl=$(此);
cloneClass=options.cloneClass;
}else if($(this).closest(“.”+options.cloneClass).size()>0){
tbl=$(this.nexist(“.”+options.cloneClass).nexist(“table”);
cloneClass=options.cloneClass;
}否则{
tbl=(this.nodeName.toLowerCase()=“table”)?$(this):$(this.closest(“table”);
}
}否则{
tbl=(this.nodeName.toLowerCase()=“table”)?$(this):$(this.closest(“table”);
}
if(options.maxRowAttr&&typeof$(this.attr(options.maxRowAttr)!=“未定义”)
options.maxRow=$(this.attr(options.maxRowAttr);
if(options.oddRowAttr&&typeof$(this.attr(options.oddRowAttr)!=“未定义”)
options.oddRowCSS=$(this.attr(options.oddRowAttr);
if(options.evenRowAttr&&typeof$(this.attr(options.evenRowAttr)!=“未定义”)
options.evenRowCSS=$(this.attr(options.evenRowAttr);
if(options.rowCountAttr&&typeof$(this.attr(options.rowCountAttr)!=“未定义”)
options.displayRowCountTo=$(this.attr)(options.rowCountAttr);
if(options.autoNumAttr&&typeof$(this.attr(options.autoNumAttr)!=“未定义”)
options.inputBoxAutoNumber=$(this.attr(options.autoNumAttr);
if(options.autoIdAttr&&typeof$(this.attr(options.autoIdAttr)!=“未定义”)
options.inputBoxAutoId=$(this.attr(options.autoIdAttr);
如果(tbl.size()>0){
if(类型待定数据(类名)==“未定义”| |待定数据(类名)==null){
etbl=新的可扩展表(tbl,options.maxRow);
if(this.nodeName.toLowerCase()!=“table”)
$(本)
.addClass(“addRow”+etbl.seed)
.数据(类名,etbl);
}否则{
if(this.nodeName.toLowerCase()!=“table”)
$(本)
.addClass(“addRow”+tbl.data(className).seed)
.数据(类名,tbl.数据(类名));
}
if($(this).data(className)){
etbl=$(this).data(className);
}
etbl.maxRow=options.maxRow;
etbl.maxRow=options.maxRow;
etbl.ignoreClass=options.ignoreClass;
etbl.rowNumColumn=options.rowNumColumn;
etbl.oddRowCSS=options.oddRowCSS;
etbl.evenRowCSS=options.evenRowCSS;
etbl.autoAddRow=options.autoAddRow;
etbl.inputBoxAutoNumber=options.inputBoxAutoNumber;
etbl.displayRowCountTo=options.displayRowCountTo;
etbl.hideFirstOnly=options.hideFirstOnly;
etbl.showFirstOnly=options.showFirstOnly;
if(typeof cloneClass==“string”&&etbl.cloneClass!=cloneClass){
etbl.cloneClass=cloneClass;
}否则{
etbl.cloneClass=“cloneRow”+etbl.seed;
}
etbl.updateRowCount();
etbl.addCallBack=回调;
};
});
对于(var i=0;i0){
tbl=$(this.nexist(“.”+options.cloneClass).nexist(“table”);
cloneClass=options.cloneClass;
}否则{
tbl=$(this.hide().closest(“表”);
}
如果(tbl.size()>0){
if(类型待定数据(类名)==“未定义”| |待定数据(类名)==null){
etbl=新的可扩展表(tbl);
$(本)
.addClass(“delRow”+etbl.seed)
.数据(类名,etbl);
}否则{
$(本)
.addClass(“delRow”+tbl.data(className).seed)
.数据(类名,tbl.数据(类名));
}
if($(this).data(className)){
etbl=$(this).data(className);
etbl.deleteCallBack=回调;
}
如果(!(etbl.cloneClass的类型==“字符串”
&&etbl.cloneClass!=“”){
etbl.cloneClass=“cloneRow”+etbl.seed;
$(this.closest(“tr”).addClass(“cloneRow”+etbl.seed);
}else if(cloneClass的类型==“字符串”){
etbl.cloneClass=cloneClass;
}否则{
etbl.cloneClass=“cloneRow”+etbl.seed;
$(this.closest(“tr”).addClass(“cloneRow”+etbl.seed);
}
etbl.update();
}
});
对于(var i=0;i)代码的目标是什么
$.fn.btnAddRow=$.fn.tableAutoAddRow=function(options,func){
var callBack;
if (typeof options=="object")
callBack=(func && $.isFunction(func)) ? func :null;
else
callBack=(options && $.isFunction(options)) ? options :null;
options=$.extend({
maxRow:null,
ignoreClass:null,
rowNumColumn:null,
autoAddRow:false,
oddRowCSS:null,
evenRowCSS:null,
inputBoxAutoNumber:false,
inputBoxAutoId:false,
displayRowCountTo:null,
maxRowAttr:null,
hideFirstOnly:null,
showFirstOnly:null,
cloneClass:null,
evenRowAttr:null,
oddRowAttr:null,
rowCountAttr:null,
autoNumAttr:null,
autoIdAttr:null
},options);
this.each(function(){
var tbl,etbl,cloneClass;
if(typeof options.cloneClass=="string" && options.cloneClass!=""){
if ($(this).closest("table").find("."+options.cloneClass).size()>0){
tbl=$(this).closest("table");
cloneClass=options.cloneClass;
}else if ($(this).closest("."+options.cloneClass).size()>0){
tbl=$(this).closest("."+options.cloneClass).closest("table");
cloneClass=options.cloneClass;
} else{
tbl=(this.nodeName.toLowerCase()=="table")?$(this):$(this).closest("table");
}
}else{
tbl=(this.nodeName.toLowerCase()=="table")?$(this):$(this).closest("table");
}
if(options.maxRowAttr && typeof $(this).attr(options.maxRowAttr)!="undefined")
options.maxRow=$(this).attr(options.maxRowAttr);
if(options.oddRowAttr && typeof $(this).attr(options.oddRowAttr)!="undefined")
options.oddRowCSS=$(this).attr(options.oddRowAttr);
if(options.evenRowAttr && typeof $(this).attr(options.evenRowAttr)!="undefined")
options.evenRowCSS=$(this).attr(options.evenRowAttr);
if(options.rowCountAttr && typeof $(this).attr(options.rowCountAttr)!="undefined")
options.displayRowCountTo=$(this).attr(options.rowCountAttr);
if(options.autoNumAttr && typeof $(this).attr(options.autoNumAttr)!="undefined")
options.inputBoxAutoNumber=$(this).attr(options.autoNumAttr);
if(options.autoIdAttr && typeof $(this).attr(options.autoIdAttr)!="undefined")
options.inputBoxAutoId=$(this).attr(options.autoIdAttr);
if(tbl.size()>0){
if(typeof tbl.data(className)==="undefined" || tbl.data(className)===null){
etbl=new ExpandableTable(tbl,options.maxRow);
if(this.nodeName.toLowerCase()!="table")
$(this)
.addClass("addRow"+etbl.seed)
.data(className,etbl);
}else{
if(this.nodeName.toLowerCase()!="table")
$(this)
.addClass("addRow"+tbl.data(className).seed)
.data(className,tbl.data(className));
}
if($(this).data(className)) {
etbl=$(this).data(className);
}
etbl.maxRow=options.maxRow;
etbl.maxRow=options.maxRow;
etbl.ignoreClass=options.ignoreClass;
etbl.rowNumColumn=options.rowNumColumn;
etbl.oddRowCSS=options.oddRowCSS;
etbl.evenRowCSS=options.evenRowCSS;
etbl.autoAddRow=options.autoAddRow;
etbl.inputBoxAutoNumber=options.inputBoxAutoNumber;
etbl.displayRowCountTo=options.displayRowCountTo;
etbl.hideFirstOnly=options.hideFirstOnly;
etbl.showFirstOnly=options.showFirstOnly;
if(typeof cloneClass=="string" && etbl.cloneClass!=cloneClass){
etbl.cloneClass=cloneClass;
} else {
etbl.cloneClass="cloneRow"+etbl.seed;
}
etbl.updateRowCount();
etbl.addCallBack=callBack;
};
});
for(var i=0;i<ExpandableTableList.length;i++){
if(!ExpandableTableList[i].goLive){
ExpandableTableList[i].live();
}
}
};
$.fn.btnDelRow=function(options,func){
var callBack;
if (typeof options=="object")
callBack=(func && $.isFunction(func)) ? func :null;
else
callBack=(options && $.isFunction(options)) ? options :null;
options=$.extend({
cloneClass:null
},options);
this.each(function(){
var etbl,tbl,cloneClass;
if ($(this).closest("."+options.cloneClass).size()>0){
tbl=$(this).closest("."+options.cloneClass).closest("table");
cloneClass=options.cloneClass;
}else{
tbl=$(this).hide().closest("table");
}
if(tbl.size()>0){
if(typeof tbl.data(className)==="undefined" || tbl.data(className)===null){
etbl=new ExpandableTable(tbl);
$(this)
.addClass("delRow"+etbl.seed)
.data(className,etbl);
}else{
$(this)
.addClass("delRow"+tbl.data(className).seed)
.data(className,tbl.data(className));
}
if($(this).data(className)) {
etbl=$(this).data(className);
etbl.deleteCallBack=callBack;
}
if(!(typeof etbl.cloneClass=="string"
&& etbl.cloneClass!="")){
etbl.cloneClass="cloneRow"+etbl.seed;
$(this).closest("tr").addClass("cloneRow"+etbl.seed);
} else if(typeof cloneClass=="string"){
etbl.cloneClass=cloneClass;
} else {
etbl.cloneClass="cloneRow"+etbl.seed;
$(this).closest("tr").addClass("cloneRow"+etbl.seed);
}
etbl.update();
}
});
for(var i=0;i<ExpandableTableList.length;i++){
if(!ExpandableTableList[i].goLive){
ExpandableTableList[i].live();
}
}
};