0

この jquery を理解しようとして、使用したいスクリプトが 2 つ見つかりましたが、それらを 1 つに結合できますか? 現在、私はそれらを別々のスクリプトタグの下に置いています。

これが最初のスクリプトです

$(function(){
        $('#navigation_horiz').delay(100).fadeIn(100);
        $('#navigation_horiz').naviDropDown({
        dropDownWidth: 'auto',  //the default width of drop down elements
        slideDownDuration: 600, //easing duration for slideDown
        slideUpDuration: 300 //easing duration for slideUp    
        });
});

これが2番目のスクリプトです

if (franchise_id==undefined) { //hide commish nav is not signed into site
     var franchise_id;
     document.write("<style type='text/css'>");
     document.write("#navigation_horiz ul li.commish { display: none; }");
     document.write("</style>");
} 
else if (franchise_id=="0000") { } //show commish nav is logged in as commish
else { // hide both if logged in as any other franchise
     document.write("<style type='text/css'>");
     document.write("#navigation_horiz ul li.commish { display: none; }");
     document.write("</style>");
}

同じ...以下の例を入れようとしましたが、まったく機能しません

    $(function(){
        $('#navigation_horiz').delay(100).fadeIn(100);
        $('#navigation_horiz').naviDropDown({
        dropDownWidth: 'auto',  //the default width of drop down elements
        slideDownDuration: 600, //easing duration for slideDown
        slideUpDuration: 300 //easing duration for slideUp    
        });
});
if (franchise_id==undefined) { //hide commish nav is not signed into site
     var franchise_id;
     document.write("<style type='text/css'>");
     document.write("#navigation_horiz ul li.commish { display: none; }");
     document.write("</style>");
} 
else if (franchise_id=="0000") { } //show commish nav is logged in as commish
else { // hide both if logged in as any other franchise
     document.write("<style type='text/css'>");
     document.write("#navigation_horiz ul li.commish { display: none; }");
     document.write("</style>");
}
});
4

3 に答える 3

2

はい、できます。最初の部分は jQuery で、2 番目の部分は生の Javascript で、すべて最上位の名前空間の下にあります。

注意する必要があるのは、jQuery コードが jQuery lib と独立したプラグイン (naviDropDown?) に依存していることだけです。そのため、 jQuery とプラグインのに組み合わせたコードを配置する必要があります。

于 2013-03-21T15:00:32.543 に答える
0

それらを単一のタグに入れることもできますが、それらを別の .js ファイルに除外して、ドキュメントの最後にロードすることをお勧めします。

于 2013-03-21T14:54:35.090 に答える
0

関数は、それを実行している場合にのみ実行可能です。

Web サイトの最初の読み込み時に 2 番目のスクリプトを読み込む場合、読み込み時に関数を呼び出すつもりがない場合は、関数に 2 番目のスクリプトを配置しないでください。

スクリプトが同じイベントを提供している場合にのみ、スクリプトを同じ関数に結合する必要があります。

于 2013-03-21T15:27:21.603 に答える