js和php里面都有一個(gè)函數(shù)eval();其作用是將參數(shù)里面的字符串當(dāng)做代碼執(zhí)行,用這個(gè)函數(shù)可以創(chuàng)建自定義的回調(diào)函數(shù)
php回調(diào)函數(shù):
/**** @param* @return**/
function a($str){echo $str;}
/**** @param* @return**/
function s($callBack){eval($callBack);}
s("a('linshaoqiang');");
exit;
js回調(diào)函數(shù):
function a(str){
alert(str);
}
function s(callBack){ with ( window )eval(callBack);
}
s("a('linshaoqiang')");