JS PHP Mutual Tuning

Source: Internet
Author: User
Tags echo date

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: &LT;? $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

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.