<!DOCTYPE html> <html> <head> <title></title> <script> var clickxx = function(){ var x = []; x.push("a"); x.push("b"); x.push("c"); x.push("d"); x.push("e"); // x.forEach(function(y){ //最终得到undefined // if(y=="e"){ // return true; // } // }); for(var i = 0;i< x.length;i++){ if(x[i]=="e"){ return true;//这里可以返回true } } } function func(){ var x = clickxx(); alert(x); } </script> </head> <body> <input type="button" οnclick="func()" value="click"/> </body> </html>
先记录下,具体原因下面继续学习。。。