1 JS way to call PHP file and get the value in PHP
Give a simple example to illustrate: in the page a.html with the following sentence call: <script type= "Text/javascript" src= "B.php?action=test" ></script>< Script type= "Text/javascript" >alert (jstext);</script> in b.php has such a section of PHP code: <? $action =$_get[' action ']; echo "var jstext= ' $action '"; Output A JS statement, generate a JS variable, and assign a value of PHP variable $action value//echo "var jstext= ' AA '"; echo "var jstext=". "' $action ' ";?> when the a.html file is executed, the b.php file is called and the output of the b.php file is executed as a JS statement, so a hint box pops up with the value of the JS variable jstext. That is, the value that is assigned to Jstext in the php file. Summary: In the HTML with the JS call file in the way the PHP file, the output of the PHP file will be called the page as JS code to use. 2 PHP calls JS value in the z.php page has such a code: <script Type= "Text/javascript" > var url= "aaaa*"; </script> <? $key = "<script type=text/javascript>document.write (URL) </script>"; echo $key; >3 php calls JS method (function) <script type= "Text/javascript" > Function test () {var t1=3; t1 = t1+2; alert (t1); /return T1; } </script><?php echo "<script type= ' Text/javascript ' >test ();</script>";? >4 JS Call php variable (1) <?php$userid=100;? > <script>var Userid;userid=docUment.getelementbyidx_x_x_x ("userid"). Value;alert (userid); </script><input type= "text" name= "UserId" id= " UserId "value=" <?php echo $userId;?> "> (2) <?php$url = ' changing URL '; Define variables? ><script type= "Text/javascript" >//js call php variable var ds = "<?php echo $url?>"; Assignment alert (DS); Output effect </script>5-------------------------------<script language= "JavaScript" > <!--var y=<?php echo Date (' Y ')? >,m=<?php echo Date (' n ')? >,d=<?php Echo Date (' J ')? >;--></script>6 Write your own JS and PHP call 1.php content: <?php//echo "<script language= ' JavaScript ' >alert (' $php variable ');</script>"; The simplest PHP call Js//echo "<a href=#></a> ";//echo" <a href= ' 3.php ' >aaaa</a> "; PHP hyperlink//echo "<script type= ' text/javascript ' language= ' JavaScript ' >phpmake (' PHP Build Station learning Note net ');</script> "; Sometimes it is necessary to invoke the JavaScript custom function during PHP execution (error in validation) echo "function ok (msg) {alert (msg);}";? .;
JS PHP Mutual tuning