JQuery. map (array, callback (elementOfArray, indexInArray ))
Returns: Array
I feel that jquery's map method is very useful. I would like to share with you.
Method: replace an array or a single object with a new content.
Application Example: Get the values of a group of checkpoints, which are separated by commas (,) and spliced.
Copy codeThe Code is as follows:
<Html>
<Head>
<Script type = "text/javascript" src = "http://code.jquery.com/jquery-1.5.1.min.js"> </script>
<Script>
$ (Function (){
$ ("Input"). click (function (){
Var str = $ (": checked"). map (function (){
Return this. value;
}). Get (). join (",")
$ ("Span" example .html (str );
})
})
</Script>
</Head>
<Body>
<Input type = "checkbox" value = "a"/>
<Input type = "checkbox" value = "B"/> B
<Input type = "checkbox" value = "c"/> c
<Br/>
Result Display: <span/>
</Body>
</Html>
I am not sure about CSDN code editing. I created the above example in jsFiddle, with the link http://jsfiddle.net/dv8eh /.