zoukankan      html  css  js  c++  java
  • jquery获取元素的值,获取当前对象的父对象等等

    Html代码

    <span><input type="hidden" value="1" id="newInfo"></input></span>
    <div class="sx_title"><a href="#" style="cursor: hand" onclick="more(this);" class="fright mr15">更多</a>英语-其他</div>        
    <div class="apps_container">
        <ul class="apps_list1_1">
            <input type="hidden" value="00070008" id="levelCode" />
            <input type="hidden" value="100000001811" id="columId" />
            <li><a href="/12580SchoolWap/article/getAritcleContent.do?id=100000031133&menuI=6&columnID=100000001811
                 &sessionid=F881AFC25986F14FEE1DDA60065C565A&levelCode=00070008">
                英语作文:The Countryside in Summer
                </a>
            </li>
     
            <input type="hidden" value="00070008" id="levelCode" />
            <input type="hidden" value="100000001811" id="columId" />
            <li><a href="/12580SchoolWap/article/getAritcleContent.do?id=100000031125&menuI=6&columnID=100000001811
                &sessionid=F881AFC25986F14FEE1DDA60065C565A&levelCode=00070008">
                英语作文:I Love Summer 
                </a>
            </li>
         </ul>
    </div>

    js代码:

    <script>
     function more(thisObj ){    
         var levelCode=$(thisObj).parent().next().children("ul").children("input").eq(0).val();    
         var menuI = $("#menuI").val();
         var newInfo = $(thisObj).parent().prev().children("input").eq(0).val();
          if(newInfo && newInfo=='1'){
              menuI=1; 
          }
         var columId=$(thisObj).parent().next().children("ul").children("input").eq(1).val();
         url="/12580SchoolWap/article/getCmsModuleList.do?levelCode="+levelCode+"&columnID="+ columId+"&menuI="+menuI;
        document.location=url;
    }
    </script>

    js 说明:

    当点击 <a href="#" style="cursor: hand" onclick="more(this);" class="fright mr15">更多</a>时,
    在js的函数中想要获取隐藏域的值
    <input type="hidden" value="00070008" id="levelCode" />
    <input type="hidden" value="100000001811" id="columId" />
    
    onclick="more(this);"这里的this 指的是当前dom元素  <a></a>标签
    
    在js的函数function more(thisObj){...}中,
    1.$(thisObj)获取<a></a>的jquery对象,
    2.$(thisObj).parent(),获取到<a></a>的父对象<div class="sx_title">...</div>
    3.$(thisObj).parent().next() 获取到<div class="apps_container">jquery对象
    4.$(thisObj).parent().next().children("ul") 获取到<ul class="apps_list1_1">jquery对象
    5.$(thisObj).parent().next().children("ul").children("input").eq(0)
    获取到<ul class="apps_list1_1">下面的第一个<input>元素:<input type="hidden" value="00070008" id="levelCode" />
    6.$(thisObj).parent().next().children("ul").children("input").eq(0).val();
    获取到<input type="hidden" value="00070008" id="levelCode" />的value值 :00070008
    7.$(thisObj).parent().next().children("ul").children("input").eq(1).val();
    获取到<ul class="apps_list1_1">下面的第二个<input>元素,
    <input type="hidden" value="100000001811" id="columId" />的值:100000001811
    8.$(thisObj).parent().prev()获取到<span></span>jquery对象
    9.$(thisObj).parent().prev().html()获取到<span></span>的内容<input type="hidden" value="1" id="newInfo"></input>
    10.$(thisObj).parent().prev().children("input").eq(0).val()获取
    <span></span>下面的第一个<input>的值,其实就一个<input>元素,即:1

    转:记录自己it路上的点点滴滴         jquery获取元素的值,获取当前对象的父对象等等

  • 相关阅读:
    ST (Sparse Table:稀疏表)算法
    P3379 【模板】最近公共祖先(LCA)
    AT1357 n^p mod m(洛谷)
    poj2018 Best Cow Fences
    P1024 一元三次方程求解
    poj2456
    poj1064
    P2047 [NOI2007]社交网络(洛谷)
    poj1734
    洛谷P2886 [USACO07NOV]牛继电器Cow Relays
  • 原文地址:https://www.cnblogs.com/wangfuyou/p/5534332.html
Copyright © 2011-2022 走看看