What's wrong with using Echo to invoke the JS function in PHP?

Source: Internet
Author: User
echo "";
?>

JS function:
function Show_div () {
document.getElementById ("Show"). style.display= "Block";
}

Div is hidden, want to use PHP call JS function to display the DIV


Reply to discussion (solution)

Call of course no problem, you need to note that the code of the JS function must be output before echo. And your id=show div is going to be output before the JS code.

Div->js->php Echo Jscode.

Can the order of PHP->DIV->JS be implemented? If I put PHP at the end of the other features will have an impact ...

PHP output Call JS when the div and JS code does not exist how it executes?
That doesn't mean you're directly on the page.



What do you think it's going to do?

Why do I use echo "";
Can the div be displayed?

Directly with echo "";
When they're not, what's the difference?

Page execution is from top to bottom: You can put the DIV and JS functions on the PHP page.

SetTimeout (' Show_div () ', 10)
The Show_div () function is called after 10 millisecond seconds. This is when the DOM is loaded.

Sorry, it's a typo.

You can put the DIV and JS functions on the PHP page.
= = "
You can put the DIV and JS functions on top of the PHP code.

Page execution is from top to bottom: You can put the DIV and JS functions on the PHP page.

SetTimeout (' Show_div () ', 10)
The Show_div () function is called after 10 millisecond seconds. This is when the DOM is loaded.
Show ();
Function Show ()
{

echo ' Hello word! ';

}
?>

What's the explanation for this?

We are talking about Div and JS in php output execution, not to discuss PHP functions, please see clearly.
According to your logic, you can write JS directly in PHP.

Reference 5 Floor jordan102 's reply:
Page execution is from top to bottom: You can put the DIV and JS functions on the PHP page.

SetTimeout (' Show_div () ', 10)
The Show_div () function is called after 10 millisecond seconds. This is when the DOM is loaded.

Show ();
Function Show ()
{

echo ' Hello word! ';

}
?......

Explain what? This is PHP, upstairs is js/html.

Reference 5 Floor jordan102 's reply:
Page execution is from top to bottom: You can put the DIV and JS functions on the PHP page.

SetTimeout (' Show_div () ', 10)
The Show_div () function is called after 10 millisecond seconds. This is when the DOM is loaded.

Show ();
Function Show ()
{

echo ' Hello word! ';

}
?......

It is estimated that your echo was output before JS. At that time, the Show_div function was not executed. • • You delay 10 seconds, the page is loaded, and the JS function naturally has
You put echo at the end of the file.

Thank you, you've figured it out.

May I ask how you solved it?

  • 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.