In php, how can I use echo to call JS functions?

Source: Internet
Author: User
In php, how can I use echo to call JS functions? & Lt ;? Php & nbsp; echo & nbsp; "& lt; script & gt; show_div (); & lt;/script & gt; ";? & Gt; js functions: in func php, how does one call JS functions with echo?
Echo "script show_div (); script";
?>

Js functions:
Function show_div (){
Document. getElementById ("show"). style. display = "block ";
}

// Div is hidden. you want to display the div by calling the JS function in php.
Share: js function: function? Show_div (){???? Document. g... 'data-pics = ''>
------ Solution --------------------
Of course there is no problem with calling. you need to note that the js function code must be output before echo, and your id = show div should be output before js code.

Div-> js-> php echo jscode.


------ Solution --------------------
When php outputs and calls js, neither div nor js code exists. how can it be executed?
This does not mean that you directly add

Script show_div (); script

What do you think it will do?
------ Solution --------------------
Page execution is from top to bottom .. You can place the div and js functions on the PHP page.

SetTimeout ('show _ div () ', 10)
The show_div () function is called 10 milliseconds later. At this time, the DOM will naturally be loaded.
------ Solution --------------------
Reference:
Page execution is from top to bottom .. You can place the div and js functions on the PHP page.

SetTimeout ('show _ div () ', 10)
The show_div () function is called 10 milliseconds later. At this time, the DOM will naturally be loaded.

Show ();
Function show ()
{

Echo 'hello word! ';

}
?>

What is this explanation?
------ Solution --------------------
We are discussing the output execution of div and js in php, rather than discussing php functions. please be clear.
Just write js directly in php according to your logic.

Reference:
Reference:
Page execution is from top to bottom .. You can place the div and js functions on the PHP page.

SetTimeout ('show _ div () ', 10)
The show_div () function is called 10 milliseconds later. At this time, the DOM will naturally be loaded.

Show ();
Function show ()
{

Echo 'hello word! ';

}
?......

------ Solution --------------------
What is the explanation? This is php, and js/html upstairs.

Reference:
Reference:
Page execution is from top to bottom .. You can place the div and js functions on the PHP page.

SetTimeout ('show _ div () ', 10)
The show_div () function is called 10 milliseconds later. At this time, the DOM will naturally be loaded.

Show ();
Function show ()
{

Echo 'hello word! ';

}
?......

------ Solution --------------------
It is estimated that your echo has been output before JS. at that time, the show_div function has not been executed. you have a delay of 10 seconds. after page loading is completed, the JS function will naturally become available.
Put ECHO at the end of the file.

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.