basic.css 定义loading样式 .loading { background: url(/NewImg/loading.gif) no-repeat center; } common.js Loading方法 var LoadingShow = function (target) { if (!$(target).hasClass('loading')) { $(target).addClass('loading'); } } var LoadingHide = function (target) { if ($(target).hasClass('loading')) { $(target).removeClass('loading'); } } //调用 $.ajax({ type: 'POST', url: '/NewHandler/HotelHandler.ashx', data: subdata, dataType: 'JSON', beforeSend: function () { $('.hotel_list').html(''); LoadingShow('.hotel_list'); }, success: function (result) { if (result.state == 1) { tempdata = result.rows; var HotelHtml = new EJS({ element: 'HotelTemplate' }).render(result.rows); LoadingHide('.hotel_list'); $('.hotel_list').html(HotelHtml); //显示每日房价 $('.btn_booking_pri').mouseover(function (e) { $('.edayPrice').show(300).css({ top: e.pageY + 10, left: e.clientX - 500 }) }).mouseout(function () { $('.edayPrice').hide() }); //每个酒店显示3条可卖房间 for (var i = 0; i < $('.roomItems').length; i++) { var currul = $('.roomItems')[i]; if ($(currul).find('.btn_booking').size() > 3) { $(currul).find('.btn_booking:gt(2)').parent().parent().parent().addClass('none'); } else { $(currul).next('.fold').addClass('none'); } }; } else { alert(result.msg); } }, error: function (e) { alert("网络错误"); } }) }