PHP can be used in js. The usage method is: 1. Open the corresponding js file; 2. Use the "<script herf="js/demo js php"></script>" method Just embed the php code in javascript.
The operating environment of this tutorial: windows7 system, PHP8.1 version, DELL G3 computer
Can I use php in js?
1. Embed php code in javascript
If javascript is included through a js file, you can also write php code directly in the js file, but the extension of the js file must be Change to php, such as
<script herf="js/demo js php"></script>
2. Default values of javascript function parameters In C language, you can set the default parameters like this
void foo(int a int b = bool c = false);
, but javascript cannot do this newGame: function(a b = )
IE and Chrome will report an error and ff will directly ignore it. We can use the arguments read-only variable array to achieve
Recommended learning: "PHP Video Tutorial"
The above is the detailed content of Can I use php in js?. For more information, please follow other related articles on the PHP Chinese website!