<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的值

解决方案 »

  1.   


    <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为什么不直接获取呢?
      

  2.   


    <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)
    });
    });
      

  3.   


    alert($(obj).parent().filter("#childThree"));
    alert($(obj).parent().children("#childThree"));
    alert($(obj).parent().find("#childThree"));