jquery map() method
Translation results:
map
英[mæp] 美[mæp]
n. Map, celestial map; something similar to a map;
vt. draw (a region, etc.) map; survey; detailed planning; [genetics] comparison
jquery map() methodsyntax
Function: map() passes each element to the current matching collection through the function and generates a new jQuery object containing the return value.
Syntax: .map(callback(index,domElement))
##Parameters:
Description | |
The function object called for each element in the current collection . |
Note: Since the return value is an array encapsulated by jQuery, use get() to process the returned object to get the underlying array.
jquery map() methodexample
<!DOCTYPE html> <html> <head> <style>p { color:red; }</style> <script type="text/javascript" src="http://apps.bdimg.com/libs/jquery/2.1.1/jquery.min.js"></script> </head> <body> <p><b>Values: </b></p> <form> <input type="text" name="name" value="John"/> <input type="text" name="password" value="password"/> <input type="text" name="url" value="http://php.cn/"/> </form> <script> $("p").append( $("input").map(function(){ return $(this).val(); }).get().join(", ") ); </script> </body> </html>
Click the "Run instance" button to view the online instance