0
$(document).ready(function()
{
    function clearTheDisplayInitial()
    {
       $(document.getElementById('Resume')).hide();
       $(document.getElementById('CodingExamples')).hide();
       $(document.getElementById('AboutMe')).hide();
    }
    function clearTheDisplay()
    {
       $(document.getElementById('Resume')).fadeOut(900);
       $(document.getElementById('CodingExamples')).fadeOut(900);
       $(document.getElementById('AboutMe')).fadeOut(900);
       $(document.getElementById('mainMenu')).fadeOut(900);

    }
        $("#displayResume").click(function()
        {
            clearTheDisplayInitial();
            $(document.getElementById('Resume')).fadeIn(900);
        });
        $("#CodingExamples1").click(function()
        {
            clearTheDisplay();
           $(document.getElementById('AboutMe')).fadeIn(900);
        });
});

2つの方法で画面をクリアできません。コンソールは関数が存在することを認識しません。フェードイン機能は使えるけど

4

1 に答える 1

1

の外側で関数を宣言することをお勧めします$(document).ready(function(){ .. });

基本的にローカル関数を作成しようとしているため、コンソールは関数の存在を認識しません。

function clearTheDisplayInitial() {
    $("#Resume, #CodingExamples, #AboutMe").hide();
}
function clearTheDisplay() {
    $("#Resume, #CodingExamples, #AboutMe, #mainMenu").fadeOut(900);
}
$(document).ready(function() {
    $("#displayResume").click(function() {
        clearTheDisplayInitial(); // you could just add $("#Resume, #CodingExamples, #AboutMe").hide(); here
        $("#Resume").fadeIn(900);
    });
    $("#CodingExamples1").click(function() {
        clearTheDisplay(); // you could just add $("#Resume, #CodingExamples, #AboutMe, #mainMenu").fadeOut(900); here
        $("#AboutMe").fadeIn(900);
    });
});

ところで、私はあなたのコードを単純化しました。関数がドキュメント準備完了関数内にある必要が本当になかったことを願っています。

于 2013-07-17T05:09:55.890 に答える