简体   繁体   English

调用javascript函数显示时没有显示Div

[英]Div is not showing when call a javascript function to show it

I am new in JavaScript & jQuery so, kindly don't mind my very basic question: 我是JavaScriptjQuery新手,所以,请不要介意我的基本问题:

I have made the following div which I want to show when certain JavaScript function being called: 我已经创建了以下div,在调用某些JavaScript函数时要显示该div:

<div id='faix' class="bg4 w460 h430 tac poa dpn">
    <h4 class="fwb fs22 cf3 mb5 ff3 mt150 ">Thank you John for contacting us!</h4><h4 class="fwb fs22 cf3 mb5 ff3"> We will get in touch with you shortly.</h4>
</div>

but when that function being called and I passed this to that function then the respective div with id of "faix" is not showing up 但是当调用该函数并将其传递给该函数时,标识为“ faix”的相应div不会显示

$('#faix').fadeIn(500);

What am I doing wrong with the above code? 上面的代码我在做什么错?

Make sure you have put the 确保已将

$('#faix').fadeIn(500);

into 进入

$(function() {
    $('#faix').fadeIn(500);
});

because it should, wenn jQuery is ready. 因为应该,jQuery已准备就绪。

Your code is ok; 您的代码还可以; I think you're calling it, when the html isn't build yet. 我认为您正在调用它,但尚未构建html。 Wrap your code in a $(document).ready : 将您的代码包装在$(document).ready中

$(document).ready(function() {
    $('#faix').fadeIn(500);
});

try to wrap your code between : 尝试在以下代码之间包装代码:

$(function(){

});

and see if your div is hidden using css by the following code for cross browser compatibility: 并通过以下代码查看是否使用CSS隐藏了div,以实现跨浏览器兼容性:

display:none;

Make sure none of those classes bg4 w460 h430 tac poa dpn says something like display:none !important or visibility:hidden !important or margin-top: -99999px that kind of stuff. 确保这些类bg4 w460 h430 tac poa dpn display:none !importantmargin-top: -99999px visibility:hidden !importantmargin-top: -99999px这样的东西。

After you make the call, use Inspector (Ctrl+Shift+I) to find the sick div and look at its CSS properties to determine whether it should be visible or something else prevents you from seeing it. 调用之后,使用Inspector(Ctrl + Shift + I)查找有病的div,然后查看其CSS属性以确定它是否应该可见,或者其他原因阻止您看到它。 Also look at Console to watch for errors, maybe it's in a train of functions and if one fail, subsequent functions fail too. 还要查看控制台以查看错误,也许是一系列功能中的一个,如果一个失败了,那么后续功能也会失败。

Check out the basic things like have you imported jquery api, putting it within document.ready function etc. 检查一下基本的东西,例如是否导入了jquery api,将其放入document.ready函数等中。

Also I remember encountering such a problem once due to a div id clashing with possibly a div name in jquery api, so try changing the div name. 我也记得一次遇到这样的问题,原因是div id与jquery api中的div名称冲突,因此请尝试更改div名称。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM