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());
}
);
精彩评论