js common method summary (after the encounter further summary)

1, index () Returns the index position of the element with respect to the other specified elements.

       <h1>店铺评价</h1>
            <div class="star starcd">
                <div>相符程度</div>
                <span ></span>
                <span ></span>
                <span></span>
                <span ></span>
                <span ></span>
            </div>
       //打星评价
       $('.starcd span').click(function(){
            var index = $(this).index();
            $('.starcd span').each(function(i,e){
                if(i<index) {
                    $(e).addClass('active');
                }else {
                    $(e).removeClass('active');
                }
            })
        });

2, each () is a predetermined function of a predetermined operation of each element match. Tip: return false can be used as soon as possible to stop the cycle.

$ (Selector) .each ( function (index, Element))         index - the position index selector      Element - The current element (can also use "this" selector)

3, the next element on an element prev () / next () specified element / elements specified

4, sub-elements parent element parent () / children () specified element / elements specified

5, siblings () returns all sibling element of the selected element, element sibling elements share the same parent element

Guess you like

Origin www.cnblogs.com/zouhong/p/11871237.html