0
我的CMS有大约30个不同的模块,下面是代码包含在每个模块的javascript中,除了一些更改外,并不知道是否有更简单的方法或我可以做的更多,以消除必须反复复制相同的代码,以防万一我必须回去改变一些东西,我只能做一次。但页面上不同的部分是任何说每个页面上的单词模板不同的部分,因为它表示模块化名称。我不知道我是否可以改变东西像itemID和其他任何东西。将所有文件的类似代码更改为一个
$('.ask').jConfirmAction({
question : "Are you sure you want to delete the selected row?",
yesAnswer : "Yes",
cancelAnswer : "No",
onYes: function(evt) {
templates(evt.target);
}
});
$('.ask2').jConfirmAction({
question : "Are you sure you want to delete all selected rows?",
questionClass: "question2",
onYes: function(evt){
templatesArray(evt.target);
}
});
function templates(whatsThis) {
var templateID = $(whatsThis).parents('td').find('img').attr('id');
var dataString = 'templateID=' + templateID + '&deleteTemplate=True';
var iRow = oTable.fnGetPosition($(whatsThis).parents('tr').get(0));
$.ajax({
type: "POST",
url: "processes/templates.php",
data: dataString,
success: function(data) {
if (data.errorsExist) {
} else {
oTable.fnDeleteRow(iRow); // remove the row from the table
if(oTable.fnSettings().fnRecordsTotal() == 0) {
$('.bt_red').remove();
$('.bt_blue').remove();
}
if(oTable.fnSettings().fnRecordsTotal() <= 10) {
$('.bt_blue').remove();
}
}
}
});
}
function templatesArray(whatsThis) {
var myNewArray = new Array();
var aRow = new Array();
$('input:checkbox[name="templates"]:checked').each(function(i) {
myNewArray.push($(this).val());
aRow.push($(this).closest('tr')[0]);
});
var dataString = 'templatesArray=' + myNewArray + '&deleteTemplatesArray=True';
$.ajax({
type: "POST",
url: "processes/templates.php",
data: dataString,
success: function(data) {
if (data.errorsExist) {
} else {
$(whatsThis).parents("tr").eq(0).hide();
for (i in aRow) // loop over the array of row indexes
oTable.fnDeleteRow(aRow[i]);
if(oTable.fnSettings().fnRecordsTotal() == 0) {
$('.bt_red').remove();
$('.bt_blue').remove();
}
if(oTable.fnSettings().fnRecordsTotal() <= 10) {
$('.bt_blue').remove();
}
}
}
});
}
为什么我的帖子编辑? –
jquery标签被添加,因为你有jQuery代码。 – Mrchief