开发者

Is there a way to trigger inline javascript execution inside some div from jquery?

开发者 https://www.devze.com 2022-12-30 06:48 出处:网络
I have some container on a page with inline javascript. Is there a way to trigger its execution once again after it was initially triggered automatically on a page load?

I have some container on a page with inline javascript. Is there a way to trigger its execution once again after it was initially triggered automatically on a page load?

<div id="mydiv">
    <script type='text/javascript'>alert("trigger me again");</scr开发者_开发知识库ipt>
</div>


You could try:

eval($('script', $('#mydiv')).text());

Just a thought


You need to make a function:

<script type='text/javascript'>
function doSomething() {
    alert("trigger me again");
}
doSomething();  //Call the function immediately
</script>

You can then call the function again somewhere else:

doSomething();


You could assign it to a function and set a timer event ... There are two types of timers in javascript (setTimeout and setInterval). However, there are also some jQuery libs for event timers.


What I would do is make that inline javascript call be a function. Then you can call that function over and over after the page load.


I guess you can select your element and then eval() the code inside.

Something like :

$('script').each(
   function() {
      eval($(this).text());
   }
);
0

精彩评论

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