3

私にはたくさんのコードがあり、ここにすべてを投稿することは避けたいと思いますが、必要に応じて、似たようなものを作成するか、モックアップします。

私の問題は、(load() を使用して) ページをロードしてから (fadeIn() を使用して) 非表示を解除する非表示の div があることです。この div を片付けるときが来たら、空のページを div にロードしてフェードアウトします。JavaScriptアラートを入れて空のページをテストしましたが、実際にロードされていますが、最初のページのdivにロードしたJavascriptはまだ実行されています. この Javascript は現在、親ページに属していますか? アンロードして実行または利用できなくする方法はありますか? 後で別の動的コンテンツを使用してページを再度読み込む必要があり、まだ実行中の Javascript が再度読み込まれるときに同じ Javascript と競合します。そしてまた。

この説明が理解できることを願っています。私の問題はおそらく非常に単純で、まだ理解していない階層に関係していると思います。

ありがとうございました!

- - - - - - - 編集

読み込まれたページの Javascript は次のとおりです。参照するすべてのクラスと ID は、ロードされたページ内に存在します。(コードは、http: //www.ilovecolors.com.ar/ によってコード化されたタブの動作から適応されます)

    //array to store IDs of our tabs
var tabs = [];
//index for array
var ind = 0;
//store setInterval reference
var inter = 0;

//change tab and highlight current tab title
function change(stringref){
    //hide the other tabs
    jQuery('.tab:not(#' + stringref + ')').hide();
    //show proper tab, catch IE6 bug
    if (jQuery.browser.msie && jQuery.browser.version.substr(0,3) == "6.0")
        jQuery('.tab#' + stringref).show();
    else 
        jQuery('.tab#' + stringref).fadeIn(200);
    //clear highlight from previous tab title
    jQuery('.htabs a:not(#' + stringref + 't)').removeClass('select');
    //highlight currenttab title
    jQuery('.htabs a[href=#' + stringref + ']').addClass('select');
}
function next(){
    alert("change");
    //call change to display next tab
    change(tabs[ind++]);
    //if it's the last tab, clear the index
    if(ind >= tabs.length)
        ind = 0;
}
jQuery(document).ready(function(){
    //store all tabs in array
    jQuery(".tab").map(function(){
        tabs[ind++] = jQuery(this).attr("id");
    })
    //set index to next element to fade
    ind = 1;
    //initialize tabs, display the current tab
    jQuery(".tab:not(:first)").hide();
    jQuery(".tab:first").show();
    //highlight the current tab title
    jQuery('#' + tabs[0] + 't').addClass('select');
    //handler for clicking on tabs
    jQuery(".htabs a").click(function(){

        //if tab is clicked, stop rotating 
        clearInterval(inter);
        //store reference to clicked tab
        stringref = jQuery(this).attr("href").split('#')[1];
        //display referenced tab
        change(stringref);
        return false;
    });
    //start rotating tabs
    inter = setInterval("next()", 3500);
});
4

1 に答える 1

1

javascriptは毎回同じであり、ロードされたページのコンテンツのみが変更されます(コンテンツが変更されるか、毎回リロードしても意味がないと思います)。そのため、divにロードされているファイルの外にスクリプトを取り出し、メインページに1回だけロードします。

于 2012-01-27T08:34:23.967 に答える