jquery Ajax方法中的.load()可以用来加载图像吗?

发布于 2024-10-09 12:21:04 字数 682 浏览 0 评论 0原文

我可以问一下 jquery ajax load 方法可以用来加载图像吗,下面是我的代码,它失败了,任何人都可以纠正它吗?

<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>

can i ask can jquery ajax load method used to load an image, below is my code and it is fail, can anybody correct it?

<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>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

清欢 2024-10-16 12:21:04

不需要。只需创建一个 img 元素,设置 src 并将其放置在您希望的位置即可。

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

演示

No. Just create a img element, set the src, and place it where you wish.

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

Demo

三生一梦 2024-10-16 12:21:04

或许

<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>

May be

<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>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文