JQuery .get メソッドを使用して、Web ページ (ページ 1) からコンテンツを取得し、メイン ページの div に表示しています。問題は、取得されたコンテンツにいくつかの JavaScript 呼び出しが含まれていることです。コンテンツは表示されていますが、Javascript メソッドが実行されていません。.js ファイルはすべてのページで参照されているため、メインでの js の可用性は問題になりません。
これは、メイン ページのコードです。ページ 1 の URL が .get 関数に渡されます。
$.get(url, function(response) {
var newContent = $(response).find("#right"); //Find the content section of the response
var contentWrapper = $("#wrap"); //Find the content-wrapper where we are supposed to change the content.
var oldContent = contentWrapper.find("#right"); //Find the old content which we should replace.
oldContent.replaceWith(newContent);
});
これは、ページ 1 の #right (div) のコードです。
Some html tags...
<p><script type="text/javascript">abc7();</script></p>
<p><script>s(30)</script></p>
Some html tags...
関数 abc7 と s は、すべてのページのセクションで参照されている .js (通常の JavaScript ファイル) で使用できます。
s(30) は、サイズ 30 のテキスト フィールドを表示する必要があります。