我使用jquery.history lugin在這裏找到:http://tkyk.github.com/jquery-history-plugin/jquery歷史插件不包括腳本?
有了這個我加載內容到一個div。但是,腳本(使用chrome webtools分析後)不包含腳本。假設我有一個名爲#content的div。如果我想page.html中加載到它和HTML頁面包含一個JavaScript代碼或包括(作爲示例)就像這樣:
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
alert("hello world");
</script>
它不會加載的jquery.js或執行警報。在webtools我反而看到它是這樣的:
你明白了。沒有。 所以它似乎排除JavaScript以某種方式,只挑出了HTML。在我jqeury.history的代碼,我只加載page.html中的某一格(.TARGET),它看起來像這樣:
(function($){
var origContent = "";
function loadContent(hash) {
$('#content').stop(true,true).fadeOut();
if(hash != "") {
if(origContent == "") {
origContent = $('#content').html();
}
$('#content').load(hash +".html .target",
function(){ $(this).prettyPrint(); });
} else if(origContent != "") {
$('#content').html(origContent);
}
$('#content').stop(true,true).fadeIn("fast");
}
$(document).ready(function() {
$.history.init(loadContent);
$('#navigation a').not('.external-link').click(function(e) {
var url = $(this).data('name');
url = url.replace(/^.*#/, '');
$.history.load(url);
return false;
});
});
})(jQuery);
最好的問候!
但是沒有辦法解決這個問題嗎?一種加載腳本標記的方法,即使它自然不允許它? – Paparappa
你基本上必須自己嘗試並實現它。沒有標誌或選項或任何可讓您告訴「.load()」運行腳本的內容。 – Pointy
[這是jQuery的bug。](http://bugs.jquery.com/ticket/6307) – Pointy