1. JS method: Call the php file and obtain the values in php. For example, use the following statement in page a.html: <script type = "text/javascript" src = "B. php? Action = test "> </script> <script type =" text/javascript "> alert (jstext); </script> there is such a php code in B. PHP: <? $ Action = $ _ GET ['action']; // echo "var jstext = '$ action'"; // output a JS statement to generate a JS variable, and assign the value of $ action to the PHP variable // echo "var jstext = 'aa'"; echo "var jstext = ". "'$ action'";?> B. PHP file, and. the output of the PHP file is executed as a JS statement. Therefore, a prompt box is displayed. The content is the value of the JS variable jstext, that is, the value assigned to jstext in the PHP file. summary: when PHP files are called by JS in HTML, the output of PHP files will be called by pages as JS Code. 2. php calls the js value in z. the php page contains the following code: <script type = "text/javascript"> var url = "aaaa *"; </script> <? $ Key = "<script type = text/javascript> document. write (url) </script>"; echo $ key;?> 3. php calls methods (functions) in js <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 calls the PHP variable (1) <? Php $ userId = 100;?> <Script> var userId; userId = document. getelementbyidx_x_x ("userId "). value; alert (userId); </script> <input type = "text" name = "userId" id = "userId" value = "<? Php echo $ userId;?> "> (2) <? Php $ url = 'changed URLs '; // define variables?> <Script type = "text/javascript"> // js calls the php variable var ds = "<? Php echo $ url?> "; // Assign values to alert (ds); // output result </script> 5 ------------------------------- <script language =" JavaScript "> <! -- Var Y = <? Php echo date ('y')?>, M = <? Php echo date ('n')?>, D = <? Php echo date ('J')?>; --> </Script> 6. Self-written js and php call each other. 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 super URL // echo "<script type = 'text/javascript 'language = 'javascript'> phpmake ('php Site Building Study note '); </script> "; // sometimes you need to call a JavaScript custom function during PHP Execution (an error occurs during verification) echo" function OK (msg) {alert (msg) ;}" ;?> <HTML> <HEAD> <TITLE> php methods for calling js files </TITLE> </HEAD> <BODY> <! -- Js calls the js defined in php --> <scr limit pt language = ''limit Cr limit pt'' type = ''text/limit Cr limit pt ''src ='' 1. php ''> </scr then pt> <scr then pt> OK (" aaaaaa! "); </Scr platinum pt> </script> </BODY> </HTML> 2. php content: <! -- Js calls php --> <? Php $ userId = 100;?> <Script> var userId; userId = document. getElementByIdx_x ("userId "). value; alert (userId); </script> <input type = "text" name = "userId" id = "userId" value = "<? Php echo $ userId;?> "> <! -- Js calls php --> <? Phpif ($ _ GET ["action"] = "OK") {echo "I'm OK! ";} Else {echo" I'm not OK! ";}?> <SCRIPT Language = "JavaScript"> function func () {if (confirm ("Are you OK with this? ") {This. location =" OK. php? Action = OK ";} else {this. location =" OK. php? Action = cancel ";}} </SCRIPT>