jquery toArray() method
Translation results:
to
英[tə] 美[tu,tə]
prep.To; toward; toward; about; belonging to
adv. in one direction; to a certain state; to close
array
英[əˈreɪ] 美[ə'reɪ]
n. array;queue,array;a large number;clothes
vt.arrangement;deployment of troops;dressing, decoration
jquery toArray() methodsyntax
Function: The toArray() method returns the elements matched by the jQuery selector in the form of an array.
Syntax: $(selector).toArray()
jquery toArray() methodexample
<html> <head> <script type="text/javascript" src="http://apps.bdimg.com/libs/jquery/2.1.1/jquery.min.js"></script> <script type="text/javascript"> $(document).ready(function(){ $("button").click(function(){ x=$("li").toArray() for (i=0;i<x.length;i++) { alert(x[i].innerHTML); } }); }); </script> </head> <body> <button>输出每个列表项的值</button> <ul> <li>Coffee</li> <li>Milk</li> <li>Soda</li> </ul> </body> </html>
Click the "Run instance" button to view the online instance