日期:2014-05-16  浏览次数:20784 次

Jquery load()加载前的友好提示 - Web 开发 / Ajax
JScript code

 $(".first_u_a").onclick(function() {
                 $("#first").empty();//清空里面的内容
                 $("#first" ).load("/temp.aspx?id=1" );//加载信息
             });


$("#first").empty();//清空里面的内容后 就没有内容了
我想在$("#first" ).load 前显示等待的图片 加载完后图片消失
不知道上面的代码怎么改
谢谢各位!

------解决方案--------------------
不用empty,直接html需要的信息即可
JScript code
$(".first_u_a").onclick(function() {
                 $("#first").html('正在加载,请稍后...');////////
                 $("#first" ).load("/temp.aspx?id=1" );//加载信息
             });

------解决方案--------------------
更通用的写法:
HTML code

 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title></title>
    <style type="text/css"></style>
    <script type="text/javascript" src="jquery.js" ></script>
    <script type="text/javascript">
        $(function(){//ajax请求开始
            var loadingTip = $('#loadingTip');
            loadingTip.ajaxStart(function(){
                loadingTip.text('loading...');
            });
            loadingTip.ajaxStop(function(){//ajax请求结束
                loadingTip.empty();
            });
            $(".first_u_a").click(function() {
                 $("#first").empty();//清空里面的内容
                 $("#first" ).load("1.html" );//加载信息
            });
        });        
    </script>
</head>

<body>
    <div id="first">原内容</div>
    <div id="loadingTip"></div>
    <a class="first_u_a">载入</a>
</body>
</html>

------解决方案--------------------

楼上正解