怎样理解jquery中常用的匿名函数的参数传递问题。

2024-12-13 09:08:13
推荐回答(1个)
回答1:

object.each( function(index, Element) )
The .each() method is designed to make DOM looping constructs concise and less error-prone. When called it iterates over the DOM elements that are part of the jQuery object. Each time the callback runs, it is passed the current loop iteration, beginning from 0. More importantly, the callback is fired in the context of the current DOM element, so the keyword this refers to the element.
这个匿名函数是each方法中的回调函数,前面的jQuery object是一个数组,each方法会对数组中子元素的逐个进行回调函数调用,直至调用某个子元素返回的结果为false为止。参数是由each方法传给回调函数的。你那段代码的意思是把$("input[name=names]:checked")数组中的数值复制到数组arr中。