Home > Web Front-end > JS Tutorial > How to write php code directly in javascript_javascript skills

How to write php code directly in javascript_javascript skills

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-05-16 17:27:39
Original
1422 people have browsed it

1. Embed php code in javascript
If javascript is included through a js file, then php code can also be written directly in the js file. However, if the js file is included, the extension must be changed to php, such as:

Copy code The code is as follows:



2. Default values ​​of javascript function parameters
In C language, you can set default parameters like this:
Copy code The code is as follows:

void foo(int a, int b = 1, bool c = false);

But javascript cannot do this:
newGame: function(a, b = 0)
ie and chrome will report an error, and ff will directly ignore it.
We can use the arguments read-only variable array to achieve this:
Copy the code The code is as follows:

function newGame(){
var a = arguments[0] ? arguments[0] : 1;
var b = arguments[1] ? arguments[1] : false;
//Function content
}
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
What are JavaScript hook functions?
From 1970-01-01 08:00:00
0
0
0
What is JavaScript garbage collection?
From 1970-01-01 08:00:00
0
0
0
c++ calls javascript
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template