【发布时间】:2011-09-23 02:22:54
【问题描述】:
可能重复:
How do I make a default value for a parameter to a javascript function
在 PHP 中:
function func($a = 10, $b = 20){
// if func() is called with no arguments $a will be 10 and $ b will be 20
}
如何在 JavaScript 中做到这一点?
如果我尝试在函数参数中赋值,我会收到错误
形式参数后缺少)
【问题讨论】:
-
简单:其中“1”是默认值。函数 abc (arg){ arg=arg===undefined?1:arg; }
标签: javascript function arguments