2010-10-27 19 views
1

加載的頁面中包含的JavaScript代碼我使用jquery.load()動態加載頁面的部分。但我希望包含的部分都包含HTML並能夠執行腳本。但是一個簡單的如何運行加載了jquery.load()

<script> 
    alert("hello"); 
</script> 

不運行的時候我AJAX它,是否有另一種方式來動態加載的內容使得腳本運行,或手動運行中包含的內容腳本的方法?在這種情況下,我依靠的方式jquery.load只包含來自加載頁面的特定選擇器。

FWIW我正在使用Jquery 1.4.2。

+2

http://stackoverflow.com/questions/235967/calling-a-jquery-function-inside-html-return-from-an-ajax-call – 2010-10-27 20:25:34

+0

[Javascript加載後不會執行]的可能重複( http://stackoverflow.com/questions/2176279/javascript-wont-execute-after-load) – 2012-08-20 09:14:18

回答

1

嘗試更改腳本加載頁面:

<script> 
    $(function(){ 
     alert("hello"); 
    }); 
</script> 

這將使得它時,它的加載運行。

+0

不幸的是,這不適合我。 $(document).ready(function(){...}); – Leopd 2010-10-27 20:39:40

+0

對不起,這是值得一試。 – 2010-10-27 21:35:28