<!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=gb2312" /> <title>無標題文檔</title> </head> <script src="http://code.jquery.com/jquery-latest.js"></script> <body> <li class="category-item"> <h2> 軟件開發 <span class="glyphicon glyphicon-menu-right" aria-hidden="true"></span> </h2> <div class="category-item-box"> <div class="category-dl"> <dl> <dt> <h3>應用軟件開發</h3> </dt> <dd> <a href="/home/project/index/cid/4053" id="4053">企業軟件(ERP)</a> <a href="/home/project/index/cid/4054" id="4054">辦公自動化OA系統</a> <a href="/home/project/index/cid/4055" id="4055">客戶關係管理(CRM)</a> <a href="/home/project/index/cid/4056" id="4056">CMS系統開發</a> </dd> </dl> <dl> <dt> <h3>軟件插件開發</h3> </dt> <dd> <a href="/home/project/index/cid/4059" id="4059">瀏覽器插件</a> <a href="/home/project/index/cid/4060" id="4060">網站插件</a> <a href="/home/project/index/cid/4061" id="4061">播放器插件</a> <a href="/home/project/index/cid/4062" id="4062">應用插件</a> </dd> </dl> </div> </div> </li> <script type="text/javascript"> <!-- $(document).ready(function(){ $(".category-item h2").click(function(){ var len = $(".category-dl dd").children().size()//獲取H2下的a標籤個數 var arr = []; for(var index = 0; index < len-1; index++){//建立一個數字數組 arr[index] = index; } $.each(arr, function(i){//循環獲得不一樣的id的值 var idValue = $(".category-dl dd").children().eq(i).attr("id"); if(idValue != ''){ alert(idValue); } }); }); }) //--> </script> </body> </html>