动态加载图像到Div [英] Loading Images into Div Dynamically

查看:138
本文介绍了动态加载图像到Div的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个配置文件列表,出现在最初通过CSS隐藏的菜单下拉div中。当选择每个菜单项时,我想动态加载这些图像(作为列表),以减少页面加载时间。这是可能的吗?

I have a list of profile images which appear in a "menu drop down" div which is initially hidden via CSS. I would like to load these images dynamically (as a list) when each menu item is selected, so as to reduce the page loading time. How is this possible?

推荐答案

尝试使用:

$("#divID").html("<img  style='position:absolute' src='path/to/the/ajax_loader.gif'>");

如果您使用ajax:

    function sendAjax()
    {
        $("#divID").html("<img  style='position:absolute' src='path/to/the/ajax_loader.gif'>");

         // you ajax code

        $("#divID").html(ajaxResponse);
    }

您还可以使用 document.getElementById('divID ').innerHTML 而不是 $(#divID)。html()。它也工作正常

you can also use document.getElementById('divID').innerHTML instead of $("#divID").html(). its also work fine

如果你使用这种方法,不需要使用CSS隐藏div。它在ajax响应后自动删除。

If you use this method, doesn't need to hide the div using css. its automatically remove after the ajax response.

这篇关于动态加载图像到Div的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆