无法从JQuery调用JavaScript函数

时间:2017-10-27 04:57:14

标签: javascript jquery call

我正在尝试从我的JavaScript Function调用jQuery Function,但它似乎没有在jQuery的末尾调用函数showMain()

见下文:我试图在showMain()函数的末尾调用.click函数。 代码:

$(document).ready(function () {  
        $('.slideshowExit').click(function () {
                setTimeout(function() {
                    $("#welcomeText").fadeOut(2000);
                },1000);
            $("#welcomePage").css("display", "none");

            //The function I am trying to Call
            showMain();
            });    




    function showMain() {
        var main= document.getElementById("mainDiv");
        main.style.display = 'block';

3 个答案:

答案 0 :(得分:4)

您应该使用匿名函数。

$(document).ready(function () {
    $('.slideshowExit').click(function () {
        setTimeout(function () {
            $("#welcomeText").fadeOut(2000);
        }, 1000);
        $("#welcomePage").css("display", "none");

        //The function I am trying to Call
        showMain();
    });
});


var showMain = function () {
    var main = document.getElementById("mainDiv");
    main.style.display = 'block';
};

答案 1 :(得分:1)

您的功能定义有误。请在函数后使用结束"}"括号。

我试图从我的jQuery函数调用我的JavaScript函数,但它似乎没有在jQuery的末尾调用函数showMain()

见下文:我试图在showMain()函数的末尾调用.click函数。代码:

$(document).ready(function () {  
    $('.slideshowExit').click(function () {
       setTimeout(function() {
       $("#welcomeText").fadeOut(2000);
    },1000);

    $("#welcomePage").css("display", "none");
    //The function I am trying to Call
    showMain();
 });    

function showMain() {
    var main= document.getElementById("mainDiv");
    main.style.display = 'block';
}

答案 2 :(得分:1)

可运行代码:

$(document).ready(function () {
    $('.slideshowExit').click(function () {
        setTimeout(function () {
            $("#welcomeText").fadeOut(500);
        }, 1000);
        $("#welcomePage").css("display", "none");

        //The function I am trying to Call
        showMain();
    });
})



    function showMain() {
        var main = document.getElementById("mainDiv");
        main.style.display = 'block';
    }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.2/jquery.min.js"></script>

<div class="slideshowExit">
  Click Here
</div>

<div id="mainDiv">
  <div id="welcomeText">Welcome to India</div>
</div>