无法在div上应用简单的隐藏功能 [英] Can't apply simple hide function on div

查看:76
本文介绍了无法在div上应用简单的隐藏功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是出于学习目的

This is for leaning purpose

我的标头中包含jQuery库:

I have jQuery library included in my header:

<script src="assets/js/jquery-1.11.0.min.js"></script>

在主体上,我有一个简单的div:

In body I have simple div:

<div id="image">
    <img class="width" src="assets/images/janka.jpg">
</div>

在正文末尾是简单的脚本:

And at the end of body is simple script:

<script>
    $("#image").load(function () { 
        $("#image").hide();         
    });
</script>

在通过jQuery函数hide()加载后,我想隐藏"image" div.但是页面加载后没有任何反应,div仍然可见.在浏览器控制台中未显示任何错误.找不到我在做什么错.请在那儿纠正我的平庸错误.

I would like to hide "image" div after loaded by jQuery function hide(). But nothing happens after page is loaded, div is still visible. In browser console is no error shown. Can't find out what I'm doing wrong. Pls, correct my banal error there.

推荐答案

load可以在Body,iframe,img等上调用,但不能在div上调用,相反,如果希望在元素上使用onload事件,则需要绑定它与元素例如.与div.但是基本上有两种方法可以调用函数 1.是在div加载后立即调用函数,在div元素后立即编写

load can be called on Body,iframe,img etc. but not on divs, Instead if you wish to use onload event on an element, you need to bind it with the element for eg. with div.But basically there are 2 ways to call a function 1. is to call function just after div load , write just after div element

       <div id="image">
            <img class="width" src="assets/images/janka.jpg">
    </div>

<script>
   function toHide() { 
        $("#image").hide();         
    }
    toHide();
    </script>

2.是要触发img而不是div的功能onload

2. is to fire function onload of img instead of div

    $("#image img").load(function () { 
                $("#image img").hide();     //USING JS function    
            });
        OR



         $("#image").load(function () { 
                $("#image").css('display', 'none');     //USING CSS   
            });

这篇关于无法在div上应用简单的隐藏功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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