jsp代码:
![](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
<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代码:
![](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
<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代码解释:
![](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
当点击 <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" /> ο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