zoukankan      html  css  js  c++  java
  • jquery点击获取子元素ID值

    <!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>
    

      

  • 相关阅读:
    Java lamda Stream
    java动态绑定的一点注意
    javascript的一点学习
    阶段总结
    some notes about spring aop
    java 命令notes
    Guava cache
    位运算
    解析JDK 7的动态类型语言支持
    Maven里面多环境下的属性过滤(配置)
  • 原文地址:https://www.cnblogs.com/xiaolinxi/p/5179086.html
Copyright © 2011-2022 走看看