Home >Web Front-end >JS Tutorial >jquery map method usage example_jquery

jquery map method usage example_jquery

WBOY
WBOYOriginal
2016-05-16 16:51:251109browse

jQuery.map( array, callback(elementOfArray, indexInArray) )

Returns: Array

I feel that jquery’s map method is very easy to use, so I would like to share it with you.

Method function: Replace an array or a single object with new content.
Application example: Get a set of checkbox values, separated by English commas, and spliced ​​together.

Copy code The code is as follows:


< head>

< script>
$(function(){
$("input").click(function(){
var str = $(":checked").map(function(){
return this.value;
}).get().join(",")
$("span").html(str);
})
})
< ;/script>


a
b
c


Result display:



I really can’t compliment CSDN’s code editing. I created the above example in jsFiddle, with the link: http:/ /jsfiddle.net/dV8eh/.
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn