开发者

How to run javascript code included in a page loaded with jquery.load()

开发者 https://www.devze.com 2023-01-22 02:25 出处:网络
I\'m using jquery.load() to dynamically load sections of a page.But I\'d like the included sections to both include HTML and be able to execute script.But a simple

I'm using jquery.load() to dynamically load sections of a page. But I'd like the included sections to both include HTML and be able to execute script. But a simple

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

doesn't run when I AJAX it in. Is there another way to dynamically load content such that the scripts will run, or a way to manually run scripts in the included content? In this case I'm relying on the way jquery.load only includes a specific selector from th开发者_Go百科e loaded page.

FWIW I'm using Jquery 1.4.2.


Try changing the script in the loaded page to:

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

This should make it run when it's loaded.

0

精彩评论

暂无评论...
验证码 换一张
取 消