在Prototype中,我可以使用以下代码显示"loading ..."图像:
var myAjax = new Ajax.Request( url, {method: 'get', parameters: pars,
onLoading: showLoad, onComplete: showResponse} );
function showLoad () {
...
}
Run Code Online (Sandbox Code Playgroud)
在jQuery中,我可以将服务器页面加载到一个元素中:
$('#message').load('index.php?pg=ajaxFlashcard');
Run Code Online (Sandbox Code Playgroud)
但是如何像在Prototype中那样将加载微调器附加到此命令?
jquery language-interoperability spinner equivalence prototypejs
也许没有区别,但要么比其他方式更好(或者可能是比两者更好的神秘'第三'方式!)......
var startTime;
$(document).ready(function() {
$("#lbl_ajaxInProgress").ajaxStart(function() {
// store the current date/time...
startTime = new Date();
// update labels
$(this).text('Yes');
$("#lbl_ajaxCallTime").text("-");
});
$("#lbl_ajaxInProgress").ajaxStop(function() {
// update labels
$(this).text('No');
$("#lbl_ajaxCallTime").text(myFunctionThatCalculatesTime(startTime));
});
});
Run Code Online (Sandbox Code Playgroud)
var startTime;
$(document).ready(function() {
$("#lbl_ajaxInProgress").ajaxStart(function() {
// update labels
$(this).text('Yes');
});
$("#lbl_ajaxInProgress").ajaxStop(function() {
// update labels
$(this).text('No');
});
$("#lbl_ajaxCallTime").ajaxStart(function() {
// store the current date/time...
startTime = new Date();
// update labels
$(this).text("-");
});
$("#lbl_ajaxCallTime").ajaxStop(function() {
// update labels
$(this).text(myFunctionThatCalculatesTime(startTime));
});
});
Run Code Online (Sandbox Code Playgroud) 我试图在使用jQuery的慢速操作期间显示一个小的加载图像,但无法正确.这是一张有数千行的大表.当我选中"mostrarArticulosDeReferencia"复选框时,它会从这些行中删除"隐藏"类.此操作需要几秒钟,我想提供一些反馈."loading"是一个带有小动画gif的div
这是完整的代码
jQuery(document).ready(function() {
jQuery("#mostrarArticulosDeReferencia").click(function(event){
if( jQuery("#mostrarArticulosDeReferencia").attr("checked") ) {
jQuery("#loading").show(); //not showing
jQuery("#listadoArticulos tr.r").removeClass("hidden"); //slow operation
jQuery("#loading").hide();
} else {
jQuery("#loading").show(); //not showing
jQuery("#listadoArticulos tr.r").addClass("hidden"); //slow operation
jQuery("#loading").hide();
}
});
jQuery("#loading").hide();
});
Run Code Online (Sandbox Code Playgroud)
看起来jquery正在"优化"这3行
jQuery("#loading").show(); //not showing
jQuery("#listadoArticulos tr.r").removeClass("hidden");
jQuery("#loading").hide();
Run Code Online (Sandbox Code Playgroud)
永远不会显示加载div.有任何想法吗?
奖励:有一种更快的方式来做这个显示/隐藏的事情吗?发现切换速度慢.
更新:我试过这个
jQuery("#mostrarArticulosDeReferencia").click(function(event){
if( jQuery("#mostrarArticulosDeReferencia").attr("checked") ) {
jQuery("#loading").show(); //not showing
jQuery("#listadoArticulos tr.r").removeClass("hidden"); //slow operation
setTimeout("jQuery('#loading').hide()", 1000);
} else {
jQuery("#loading").show(); //not showing
jQuery("#listadoArticulos tr.r").addClass("hidden"); //slow operation
setTimeout("jQuery('#loading').hide()", 1000);
}
});
Run Code Online (Sandbox Code Playgroud)
这就是我得到的
更新2:我有一个有效的解决方案.但为什么我必须使用setTimeout才能使它工作超出我的意义......
jQuery("#mostrarArticulosDeReferencia").click(function(event){
if( jQuery("#mostrarArticulosDeReferencia").attr("checked") ) …Run Code Online (Sandbox Code Playgroud)