I put these code in the HEAD part of a html,but cannot run correctly,
is there any problem?
obviously it’s a timer but it doesn’t run even once.
I didnot forget to link the jquery.
thanks a lot.
<script type="text/javascript">
$(function(){
function something(){
alert("something happened");
}
var timer=function(){
something();
setTimeout(timer,900);
};
timer;
}
);
</script>
Your outer anonymous function is run onready, but it just defines two function and then has a useless
timerexpression, you have to actually call the function:timer().If you want to do this properly, you should probably get rid of the
timerfunction entirely, as you seem to be trying to simulatesetInterval.