jQuery end()インスタンス

2110 ワード

例1、
<body>
  <p><span>Hello</span>, how are you?</p>
  <script>$("p").find("span").end().css("border", "2px red solid");</script>
</body>

//  
//$("p").find("span")    P    SPAN  
//      P   ,        P  (  SPAN   P,          )
//$("p").find("span").end()         。
//$("p").find("span").end().css("border", "2px red solid") P      。

例2、
<div id="test">  
    <h1>jQuery end()  </h1>  
    <p>  jQuery end()  。</p>  
</div>
<scripg>
$(document).ready(function() {   
    $("#test").click(function() {   
        $(this).find("p").hide().end().hide();   
    });   
});
</script>

//    //  id test div ,    div   p  ,    。 //     end()      p     ,      #test(jQuery  ),     hide()     div。

例3、


<script type="text/javascript">
    $(function(){
        $('<input type="button" value="click me" /><input type="button" value="triggle click me" /><input type="button" value="detach handle" /><input type="button" value="show/hide text" />').appendTo($('body'));
        $('input[type="button"]').eq(0).click(function(){
            alert('you clicked me!');
        })
        .end().eq(1).click(function(){
            $('input[type="button"]:eq(0)').trigger('click');
        })
        .end().eq(2).click(function(){
            $('input[typw="button"]:eq(0)').unbind('click');
        })
        .end().eq(3).toggle(function(){
            $('.panel').hide('slow');
        },function(){
            $('.panel').show('slow');
        });
    })
</script>
<div class="panel">welcome to jQuery!</div>

参考資料:jQuery end()http://www.studyofnet.com/news/932.html