Run a JavaScript function from a php if statement

后端 未结 5 2229
余生分开走
余生分开走 2020-12-04 01:39

I am using PHP conditions and want to know if I can run a JavaScript function without some one have to click on it using JavaScript:

if($value == 1)             


        
5条回答
  •  失恋的感觉
    2020-12-04 02:21

    First of all keep in mind that your PHP code is evaluated on the server, while JavaScript runs in the browser on the client-side. These evaluations happen in different places, at different times. Therefore you cannot call a JavaScript function from PHP.

    However with PHP you can render HTML and JavaScript code such that it is only rendered when your PHP condition is true. Maybe you may want to try something like this:

    if($value == 1) {
       echo "";
    } 
    

提交回复
热议问题