PHP calls JS timer problem.

Source: Internet
Author: User
The Test.js code is as follows:
var i = 0;
function Fun ()
{
document.write (i);
document.write ("\ n");
i++;
}
function Javatime ()
{
SetInterval (' Fun () ', 2000);
}


The test.php code is as follows:




<title>Untitled Document</title>



echo ""

?>




Why the JS timer executes only once, and then the browser stays in this state:
Show only 0, then the browser has been turning ...


Reply to discussion (solution)

I don't know much about JS. A change in the number of alert (i) is strange.

Landlord, you are not IE kernel browser try, such as the chrome kernel, you can get the effect you want, but the line is not \ n
[img=http://] [/IMG]

Effect

 
  Untitled Document
 
  

You read it like that. I have no problem with the test.

Upstairs says yes, it's all nonsense!
When the page loading is complete, the document of the page's carrier will be closed
The later document.write will be written in the new document.
Although non-IE series browser only the body node as the root of document, JS is still executed on the surface, but the original contents of the body is no longer exist

So as long as the page load is completed before the execution of JS, can only use InnerHTML, innerText operation page content or alert display information

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.