weixin_33724570 2015-08-20 13:28 采纳率: 0%
浏览 19

单击JS加载图像

I need to load an image, js need to get link url and print this image on screen. But it is not working.

What is wrong with my script? what can I do to make it work and improve it?

html

<div id=img></div>

<div id=loading></div>


<a href=http://png-5.findicons.com/files/icons/1580/devine_icons_part_2/128/my_computer.png class=postmini>Open image 1</a>
<br>
<a href=http://www.iconshock.com/img_jpg/BETA/communications/jpg/256/smile_icon.jpg class=postmini>Open image 2</a>

js

$(function() {
$(".postmini").click(function(){

var element = $(this);
var I = element.attr("href");

$("#loading").html('<img src="loader.gif" align="absmiddle">&nbsp;loading...');

$("#loading").ajaxComplete(function(){}).slideUp();
$("#img").append(I);

 });
});

https://jsfiddle.net/u6j2udzb/

and this loading div, what I need to do to make it work properly?

  • 写回答

5条回答 默认 最新

  • weixin_33737134 2015-08-20 13:34
    关注

    You are not running an ajax script. ajaxComplete is only fired after an ajax script completed.

    Whenever an Ajax request completes, jQuery triggers the ajaxComplete event. Any and all handlers that have been registered with the .ajaxComplete() method are executed at this time.

    You should ad an ajax script and than ajaxComplete will run if you registered the ajaxComplete method.

    评论

报告相同问题?