一、在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