1, in PHP, sometimes we need to echo out the JS script, and this script with PHP settings variables
How to output, a bit fastidious, write down to spare. Here's how:
(1) The first method
<?php
$_HG = ' Hong ';
Echo ' <script type= "Text/javascript" >alert ("My name is '. $_hg. '"); History.back ();</script> ';
?>
(2) The second method, the implementation of changing single quotation marks, the quotation of double quotes <?php $_hg = ' Hong '; echo "<script type= ' text/javascript ' >alert (' My name is '. $_hg. '); </script> ";? >
2. We encapsulate the above PHP code into a function, passing in arguments with strings
$_hg= ' Hong ';
function _alert_look ($_hh) {
echo "<script type= ' text/javascript ' >alert ('". $_hh. "); </script> ";
}
We call the function to do this:
_alert_look ("My Name is". $_hg. " Complete! ");
PHP output JavaScript script with PHP parameter, function argument string with variable