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.