让 2 个处理程序使用 jquery 触发一个函数
Have 2 handlers trigger a one function with jquery
我有一个 bootstrap javascript table 当前在文档准备好时加载,如下所示:
$(document).ready(function(){
$('#table-javascript').bootstrapTable({
method: 'get',
url: 'bootstrap_database.php',
height: 600,
cache: false,
striped: true,
pagination: true,
search: true,
pageSize: 20,
pageList: [20, 40, 60, 100, 200],
minimumCountColumns: 2,
clickToSelect: true,
columns: [{
field: 'ID',
title: 'ID',
align: 'center',
visible: false
},{
field: 'title',
title: 'Title',
align: 'center',
sortable: true,
width: '20'
},{
field: 'audio',
title: 'Audio',
align: 'center',
width: '20'
},{
field: 'sheet1',
title: 'Sheet 1',
align: 'center',
width: '20'
},{
field: 'sheet2',
title: 'Sheet 2',
align: 'center',
width: '20'
},{
field: 'sheet3',
title: 'Sheet 3',
align: 'center',
width: '20'
},{
field: 'lyrics',
title: 'Lyrics',
align: 'center',
width: '20'
},{
field: 'sheet1notes',
title: 'Notes 1',
align: 'center',
width: '20'
},{
field: 'sheet2notes',
title: 'Notes 2',
align: 'center',
width: '20'
},{
field: 'sheet3notes',
title: 'Notes 3',
align: 'center',
width: '20'
}],
aoColumnDefs: [{
bSearchable: false,
bVisible: true,
aTargets: [0]
}]
});
});
我想在我页面的其他部分重新加载 table。我的想法是有几个可以触发此功能的处理程序。也许 .click()
或 .change()
可以做到。但是我不确定我是否可以让多个处理程序触发相同的功能。
这是一个 ajax 调用的示例,我想在 success
:
之后刷新 table
$( "#addnewsong" ).on( "submit", function( event ) {
$('.newsongupprog').replaceWith('<i class="fa fa-spin fa-spinner"></i>');
thisdata = new FormData($("#addnewsong")[0]);
$.ajax({
url: "multiple_upload_ac.php?",
data: thisdata,
type : "post",
cache: false,
contentType: false,
processData: false,
success: function(data){
$('.fa-spinner').replaceWith('<i class="fa fa-check"></i>');
$('.fa-check').replaceWith('<i class="fa fa-cloud-upload"></i>');
if (data == 'go') {
data = "Your song has been uploaded";
} else {
data = "There was a problem uploading some of your files, please search for your song title and add your files manually";
}
$('div.alert3').fadeIn();
$('div.alert3').html(data);
$('div.alert3').delay(5000).fadeOut();
$table.bootstrapTable('refresh', {
url: 'bootstrap_database.php'
});
},
});
return false;
});
我觉得我的方法有点不对劲,所以我可以找一些专家来解释一下吗。
您必须先声明 $table
变量 ,然后 您尝试在 [=18= 中使用它(refresh
table) ] success
回调
$(document).ready(function(){
// declare $table variable:
var $table = $('#table-javascript').bootstrapTable({
// ... configuration ...
});
//then submit event handler:
$( "#addnewsong" ).on( "submit", function( event ) {
// ...
});
});
我有一个 bootstrap javascript table 当前在文档准备好时加载,如下所示:
$(document).ready(function(){
$('#table-javascript').bootstrapTable({
method: 'get',
url: 'bootstrap_database.php',
height: 600,
cache: false,
striped: true,
pagination: true,
search: true,
pageSize: 20,
pageList: [20, 40, 60, 100, 200],
minimumCountColumns: 2,
clickToSelect: true,
columns: [{
field: 'ID',
title: 'ID',
align: 'center',
visible: false
},{
field: 'title',
title: 'Title',
align: 'center',
sortable: true,
width: '20'
},{
field: 'audio',
title: 'Audio',
align: 'center',
width: '20'
},{
field: 'sheet1',
title: 'Sheet 1',
align: 'center',
width: '20'
},{
field: 'sheet2',
title: 'Sheet 2',
align: 'center',
width: '20'
},{
field: 'sheet3',
title: 'Sheet 3',
align: 'center',
width: '20'
},{
field: 'lyrics',
title: 'Lyrics',
align: 'center',
width: '20'
},{
field: 'sheet1notes',
title: 'Notes 1',
align: 'center',
width: '20'
},{
field: 'sheet2notes',
title: 'Notes 2',
align: 'center',
width: '20'
},{
field: 'sheet3notes',
title: 'Notes 3',
align: 'center',
width: '20'
}],
aoColumnDefs: [{
bSearchable: false,
bVisible: true,
aTargets: [0]
}]
});
});
我想在我页面的其他部分重新加载 table。我的想法是有几个可以触发此功能的处理程序。也许 .click()
或 .change()
可以做到。但是我不确定我是否可以让多个处理程序触发相同的功能。
这是一个 ajax 调用的示例,我想在 success
:
$( "#addnewsong" ).on( "submit", function( event ) {
$('.newsongupprog').replaceWith('<i class="fa fa-spin fa-spinner"></i>');
thisdata = new FormData($("#addnewsong")[0]);
$.ajax({
url: "multiple_upload_ac.php?",
data: thisdata,
type : "post",
cache: false,
contentType: false,
processData: false,
success: function(data){
$('.fa-spinner').replaceWith('<i class="fa fa-check"></i>');
$('.fa-check').replaceWith('<i class="fa fa-cloud-upload"></i>');
if (data == 'go') {
data = "Your song has been uploaded";
} else {
data = "There was a problem uploading some of your files, please search for your song title and add your files manually";
}
$('div.alert3').fadeIn();
$('div.alert3').html(data);
$('div.alert3').delay(5000).fadeOut();
$table.bootstrapTable('refresh', {
url: 'bootstrap_database.php'
});
},
});
return false;
});
我觉得我的方法有点不对劲,所以我可以找一些专家来解释一下吗。
您必须先声明 $table
变量 ,然后 您尝试在 [=18= 中使用它(refresh
table) ] success
回调
$(document).ready(function(){
// declare $table variable:
var $table = $('#table-javascript').bootstrapTable({
// ... configuration ...
});
//then submit event handler:
$( "#addnewsong" ).on( "submit", function( event ) {
// ...
});
});