Home  >  Article  >  Web Front-end  >  javascript中直接写php代码的方法_javascript技巧

javascript中直接写php代码的方法_javascript技巧

WBOY
WBOYOriginal
2016-05-16 17:27:391294browse

 一、在javascript中嵌入php代码
javascript若是通过js文件包含进来的,那么js文件中也可以直接写php代码,只不过包含js文件是扩展名要改成php,如:

复制代码 代码如下:



二、javascript函数参数的默认值
c语言中可以通过这样来设置默认参数:
复制代码 代码如下:

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

但是javascript却不能这样:
newGame : function(a, b = 0)
ie和chrome会报错,ff会直接忽略。
我们可以用arguments只读变量数组来实现:
复制代码 代码如下:

function newGame(){
var a = arguments[0] ? arguments[0] : 1;
var b = arguments[1] ? arguments[1] : false;
//函数内容
}
Statement:
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