jquery获取元素的值,获取当前对象的父对象等等

<span style="font-family: Arial, Helvetica, sans-serif;"><span><input type="hidden" value="1" id="newInfo"></input></span></span>
<div class="sx_title"><a href="#" style="cursor: hand" οnclick="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" οnclick="more(this);" class="fright mr15">更多</a>时,
在js的函数中想要获取隐藏域的值
<input type="hidden" value="00070008" id="levelCode" />
<input type="hidden" value="100000001811" id="columId" />

οnclick="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


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值