1<! DOCTYPE html>23 45<meta charset= "UTF-8" >6<title>rem Phone test</title>7<meta name= "viewport" content= "User-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0" >8<style>9*{margin:0;padding:0}Ten body{ Onefont-size:12px; A } - p{ -font-size:14px; the } - . Demo{width:rem;height:20rem;background: #00f} - ul LI{WIDTHL} -</style> + - + A<body> at -<div class= "Demo" > -<ul> -<li></li> -<li></li> -<li></li> in<li></li> -<li></li> to</ul> +</div> -<script src= "Http://libs.useso.com/js/jquery/1.8.3/jquery.min.js" ></script> the<script> * varA = [1,1,1,1,1,1,1]; $ //the parameter order of the foreach and map is exactly the opposite of the jquery each $.each order , and the order of JS is the first element and then the indexPanax NotoginsengA.foreach (function(element,index) { - Console.log (element); the }); + varb = A.map (function(element,index) { A return2 the }); + Console.log (b); - //The order of jquery is first index and then element, and $.each can pass other parameters besides passing index and element . $ //index and element will fail; $ //Note that when you use. Each, you need to convert the array to a jquery array; -$(function(){ -$ (a). each (function(index,element) { the Console.log (Element) - });Wuyi the$.each (A,function(index,element) { - Console.log (element); Wu //If you need to operate the jquery method on element, you need to write it in this way and convert it to a jquery object; - //Console.log ($ (element)) About }); $ - //$.each Pass other parameter usage; -$.each (A,function(e1,e2,e3) { - Console.log (E2); A +},[11,22,33]) the }); - $</script> the</body> the theRelated articles:
Http://www.cnblogs.com/mabelstyle/archive/2013/02/19/2917260.html
JS native foreach, map and jquery each, $.each difference