這應該是相當簡單的,但要確保...如何在不需要參數時調用函數?什麼是正確的做法
function load_img(src, alt, el, other_src) {
// check if other_src exists, not null, defined, not empty, etc...
}
//call the function
load_img(src, alt, '#zoom-cover');
是該行的方式調用該函數不需要參數時..
應該寫些什麼:
load_img(src, alt, '#zoom-cover', null);
或
load_img(src, alt, '#zoom-cover', '');
有類似像PHP
東西load_img(src, alt, '#zoom-cover', other_src='default value');
and ...我如何檢查,在函數中,other_src存在,定義,有一個有效的值,是不是空或空字符串?
'undefined!=='undefined''未定義不是字符串。 – DanMan 2011-03-10 18:37:32
只是爲了澄清:如果你測試未定義的變量的值,它是:'if(other_src!== undefined)'。像上面的字符串一樣使用它只能起作用,因爲'typeof'總是返回一個字符串。我曾經在一開始就弄錯了。 – DanMan 2011-03-10 18:45:59