日期:2014-05-16 浏览次数:20431 次
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script> <script type="text/javascript"> var glob_oplist = new Array(); $(document).ready(function() { $('#test1').each( function() { $(this).children("option").each( function() { glob_oplist.push($(this).text()) } ) } ) alert(JSON.stringify(glob_oplist)) } ) </script> </head> <body> <select id="test1"> <option>1</option> <option>2</option> <option>3</option> <option>4</option> </select> </body> </html>
------解决方案--------------------
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.js"></script> <script> $(document).ready(function(){ var ar=new Array(); $("#test1").children("option").each(function(){ ar.push($(this).text()); }); alert(ar); }); </script> <select id="test1"> <option>1</option> <option>2</option> <option>3</option> <option>4</option> </select>