【问题标题】:can .load() in jquery Ajax method use to load an image?jquery Ajax 方法中的 .load() 可以用来加载图像吗?
【发布时间】:2010-12-29 10:07:06
【问题描述】:

请问可以用jquery ajax加载方法来加载图片吗,下面是我的代码,失败了,谁能改正?

<html>
<head>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
$(document).ready(function(){
  $("div").ajaxStart(function(){
    $(this).html("<img src='http://www.w3schools.com/jquery/demo_wait.gif' />");
  });
  $("button").click(function(){
    $("div").load("http://www.google.com/images/logos/ps_logo2.png/");
  });
});
</script>
</head>
<body>

<div><h2>Let AJAX change this text</h2></div>
<button>Change Content</button>

</body>
</html>

【问题讨论】:

    标签: javascript jquery image methods load


    【解决方案1】:

    没有。只需创建一个img 元素,设置src,然后将其放置在您希望的位置。

    $("div").empty().append($("<img/>", {src: "http://www.google.com/intl/en_ALL/images/srpr/logo1w.png"}));
    

    Demo

    【讨论】:

    • 我想要的是在加载大图像时,而不是观看图像加载,我想要一个预加载器,直到图像完全加载。谢谢!!
    • @drama,那么您可能会发现 this question 很有帮助。
    【解决方案2】:

    可能

    <html>
    <head>
    <script type="text/javascript" src="jquery.js"></script>
    <script type="text/javascript">
    $(document).ready(function(){
      $("div").ajaxStart(function(){
        $(this).html("<img src='http://www.w3schools.com/jquery/demo_wait.gif' />");
      });
      $("button").click(function(){
        $("div").html("<img src='http://www.w3schools.com/jquery/demo_wait.gif' />");
      });
    });
    </script>
    </head>
    <body>
    
    <div><h2>Let AJAX change this text</h2></div>
    <button>Change Content</button>
    
    </body>
    </html>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-01-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-02-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多