<script>
function test(id=0){
alert(id);
}
</script>
<input type="button" value="test" onclick="test()">
运行结果报错,JS中不能这样传默认参数,上网查了一下,可以借助于arguments 实参数组,参考下例:
- <script>
- function test(a){
- var b=arguments[1]?arguments[1]:50
- return a+':'+b
- }
- alert(test(5))
- alert(test(5,9))
- </script>