请教jquery 父级下的某一个子级怎么取得

wenlong_15 2010-06-07 11:59:54
<div id="parentID">
<div id="childOne">one</div>
<div id="childTwo">two</div>
<div id="childThree">three</div>
<div id="childFour">four</div>
<input type="button" id="btn" />
</div>

比如说通过btn的click事件拿到childThree的值
...全文
253 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
pt1314917 2010-06-07
  • 打赏
  • 举报
回复



<div id="parentID">
<div id="childOne">one</div>
<div id="childTwo">two</div>
<div id="childThree">three</div>
<div id="childFour">four</div>
<input type="button" id="btn" onclick="shows(this);"/>
</div>

<script>
function shows(obj)
{
alert($(obj).parent().children().eq(2).text());
}
</script>


弱弱的问句:有id为什么不直接获取呢?
北京不不 2010-06-07
  • 打赏
  • 举报
回复
$("div:last").prevAll("eq(2)")
hoojo 2010-06-07
  • 打赏
  • 举报
回复

alert($(obj).parent().filter("#childThree"));
alert($(obj).parent().children("#childThree"));
alert($(obj).parent().find("#childThree"));
passself 2010-06-07
  • 打赏
  • 举报
回复

<div id="parentID">
<div id="childOne">one</div>
<div id="childTwo">two</div>
<div id="childThree">three</div>
<div id="childFour">four</div>
<input type="button" id="btn" />
</div>

子元素

$(function(){
$("#btn").click(function(){
var text = $(this).parent().children("#childThree").text();
alert(text);
var text1 = $(this).parent().children(":eq(2)").text();
alert(text1)
});
});
yingzhilian2008 2010-06-07
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 pt1314917 的回复:]
HTML code

<div id="parentID">
<div id="childOne">one</div>
<div id="childTwo">two</div>
<div id="childThree">three</div>
<div id="childFour">four</div>
<input type="button" id="btn" onclick=……
[/Quote]up
wenlong_15 2010-06-07
  • 打赏
  • 举报
回复
因为数据是循环的

87,907

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧