與Java中的傳參幾乎完全一致
~~~
<script type="text/javascript">
fn1(100);
function fn1(a){alert(a);}//100
</script>
~~~
~~~
<script type="text/javascript">
function fn(w,d){
w.onload = function(){
d.body.innerHTML = 123;
}
}
fn(window,document);
</script>
~~~
~~~
<script type="text/javascript">
//函數也能作為參數
fn(function() {
alert(1)
});
function fn(a) {
if(typeof a === 'number' && a === a) { //NaN也是number,a===a就是排除NaN
alert(a + 20);
} else if(typeof a === 'String') {
alert(a.charat(2));
} else
if(typeof a === 'function') {
a();
}
}
</script>
~~~
課堂練習-1:圖片切換,那之前做的練習,將其變成2份,利用傳參完成
課堂練習-2:模擬購物車點擊增加數量
***
課后作業-1:購物車拓展

拓展練習:
