简体   繁体   English

我如何在jQuery中使用它

[英]How i can use this in jquery

in my HTML i want change class , but i have more sections ,so i want to effect the section waht i mouseover !!! 在我的HTML中,我想更改类,但是我有更多部分,所以我想在鼠标悬停时影响该部分!

<section class="grid example">
                        </div>
                        <div class="row grids">
                            <p class="design">Footer</p><p class="source">row</p>
                        </div>
                    </div>
                </section> <!-- End example 1 -->

in jQuery i want use this to effect one section 在jQuery中,我想用它来实现一个部分

$(function(){
$('section.example').mousemove(function() {
        $('section.example p.source').css({
            display: 'block'
        });
        $('section.example p.design').css({
            display: 'none'
        });
    });

    $('section.example').mouseleave(function() {
        $('section.example p.source').css({
            display: 'none'
        });
        $('section.example p.design').css({
            display: 'block'
        });
    });
});

use this 用这个

$(this).find('p.source').css({
        display: 'block'
    });

First you can choose specific element, and then you can use $(this).children('p.source') instead of $('section.example p.design') every time. 首先,您可以选择特定的元素,然后可以$(this).children('p.source')使用$(this).children('p.source')代替$('section.example p.design') It will give you possibility to edit that one specific element, not all which have specified classes. 它将使您可以编辑该特定元素,而不是所有具有指定类的元素。

Here is a jsfilddle 这是一个jsfilddle

You have two unbalanced </div> elements that I have removed in the fiddle. 我在提琴中删除了两个不平衡的</div>元素。

You probably want to use mouseenter rather than mousemove . 您可能要使用mouseenter而不是mousemove

Other than that you want to use find as already described by Rohit. 除了您要使用Rohit所描述的find

HTML: HTML:

<section class="grid example">                        
    <div class="row grids">
        <p class="design">Footer</p>
        <p class="source">row</p>
    </div>                    
</section> <!-- End example 1 -->

Javascript: Javascript:

$(function(){
   $('section.example').mouseenter(function() {    
        $(this).find('p.source').css({
            display: 'block'
        });
       $(this).find('p.design').css({  
            display: 'none'
        });
    });

    $('section.example').mouseleave(function() {

        $(this).find('p.source').css({   
            display: 'none'
        });
        $(this).find('p.design').css({
            display: 'block'
        });
    });
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM