2016-10-27 19 views
1

、私は以下のコードを使用してリロードするページがあります。

restart_btn.click(function() { 
    location.reload(); 
}); 

をしかし、私は、ページをリロードせずに、唯一$(document).ready();を再実行したいと思います。これは可能ですか?

+3

入れ、その機能を思い出しますか? - あなたが達成したいことを見るのは難しい。 –

+0

文書は以前の準備ができているため、すぐに再作成することはできません。 – learner

答えて

1

新しい機能の中で現在ドキュメント準備機能にある現在のすべてのスクリプトをラップします。ドキュメント上でこの機能を呼び出すと、また、クリックイベントが発生します。以下

例:あなたが関数内で().readyで持っているものは何でも

function ReadyFunctionScripts() { 
    // All the scripts that are now in document ready goes here 
    // ... 

    // Clicking on button will run the scripts that were executed during document ready 
    restart_btn.one('click', ReadyFunctionScripts); 
} 

// Call the function once on document ready 
$(document).ready(ReadyFunctionScripts); 
+0

edit: 'restart_btn'変数が無効です。セレクタに変更するか、新しい関数に入れてください。 –

+0

@SamuelLiew編集のおかげで、OPは 'restart_btn'の詳細を提供していなかったので、私は' restart_btn'が有効であると仮定して彼のコードを続けました.. –

+0

編集:これを代わりに行います。 –

関連する問題