📜  如何使用 jQuery 更改 mouseenter 和 mouseleave 段落的字体样式?

📅  最后修改于: 2021-11-25 03:10:24             🧑  作者: Mango

jQuery 是强大的 JavaScript 库之一,它具有许多强大的方法,可以使用选择器更简单地操作 DOM。

在本文中,让我们看看如何使用 jQuery 在鼠标进入和鼠标离开时更改段落的字体粗细和颜色的不同方法。

方法:使用 jQuery 我们可以在 DOM 事件期间添加许多功能。我们可以使用 jQuery 添加 CSS 动画,如隐藏、显示和许多其他效果。

我们可以添加含有使用addClass()方法MouseEnter事件的CSS类和删除使用removeClass() 在 mouseleave 事件上通过选择p标签选择器。

方法 1:在 mouseenter 和 mouseleave 事件上添加单独的函数。

句法:

$('selector').eventname(function())
HTML


  

    
    
    
  
    
    
      
    

  

    

Geeks for Geeks

       

        When compared with C++, Java codes are          generally more maintainable because Java          does not allow many things which may          lead bad/inefficient programming if used         incorrectly. For example, non-primitives          are always references in Java. So we          cannot pass large objects(like we can do          in C++) to functions, we always pass         references in Java. One more example,          since there are no pointers, bad memory          access is also not possible.     

       

        Python is a high-level, general-purpose          and a very popular programming language.         Python programming language (latest          Python 3) is being used in web development,         Machine Learning applications, along with          all cutting edge technology in Software          Industry. Python Programming Language is          very well suited for Beginners, also for          experienced programmers with other          programming languages like C++ and Java.     

          


HTML


  

    
    
    
  
    
    
  
    

  

    

Geeks for Geeks

       

        When compared with C++, Java codes are         generally more maintainable because Java         does not allow many things which may         lead bad/inefficient programming if used         incorrectly. For example, non-primitives         are always references in Java. So we         cannot pass large objects(like we can do         in C++) to functions, we always pass         references in Java. One more example,         since there are no pointers, bad memory         access is also not possible.     

       

        Python is a high-level, general-purpose         and a very popular programming language.         Python programming language (latest         Python 3) is being used in web development,         Machine Learning applications, along with         all cutting edge technology in Software         Industry. Python Programming Language is         very well suited for Beginners, also for         experienced programmers with other         programming languages like C++ and Java.     

          


HTML


  

    
    
    
  
    
    
  
    

  

    

Geeks for Geeks

       

        When compared with C++, Java codes are         generally more maintainable because Java         does not allow many things which may         lead bad/inefficient programming if used         incorrectly. For example, non-primitives         are always references in Java. So we         cannot pass large objects(like we can do         in C++) to functions, we always pass         references in Java. One more example,         since there are no pointers, bad memory         access is also not possible.     

       

        Python is a high-level, general-purpose         and a very popular programming language.         Python programming language (latest         Python 3) is being used in web development,         Machine Learning applications, along with         all cutting edge technology in Software         Industry. Python Programming Language is         very well suited for Beginners, also for         experienced programmers with other         programming languages like C++ and Java.     

          


输出:

方法二:使用on() 具有多个事件的方法。

句法:

$('selector').on({
    event1:function () {
        // Code
    },
    event2:function () {
        // Code
    }
})

HTML



  

    
    
    
  
    
    
  
    

  

    

Geeks for Geeks

       

        When compared with C++, Java codes are         generally more maintainable because Java         does not allow many things which may         lead bad/inefficient programming if used         incorrectly. For example, non-primitives         are always references in Java. So we         cannot pass large objects(like we can do         in C++) to functions, we always pass         references in Java. One more example,         since there are no pointers, bad memory         access is also not possible.     

       

        Python is a high-level, general-purpose         and a very popular programming language.         Python programming language (latest         Python 3) is being used in web development,         Machine Learning applications, along with         all cutting edge technology in Software         Industry. Python Programming Language is         very well suited for Beginners, also for         experienced programmers with other         programming languages like C++ and Java.     

          

输出:

方法 3:对所选元素的mouseentermouseleave事件应用 CSS 方法。

HTML



  

    
    
    
  
    
    
  
    

  

    

Geeks for Geeks

       

        When compared with C++, Java codes are         generally more maintainable because Java         does not allow many things which may         lead bad/inefficient programming if used         incorrectly. For example, non-primitives         are always references in Java. So we         cannot pass large objects(like we can do         in C++) to functions, we always pass         references in Java. One more example,         since there are no pointers, bad memory         access is also not possible.     

       

        Python is a high-level, general-purpose         and a very popular programming language.         Python programming language (latest         Python 3) is being used in web development,         Machine Learning applications, along with         all cutting edge technology in Software         Industry. Python Programming Language is         very well suited for Beginners, also for         experienced programmers with other         programming languages like C++ and Java.     

          

输出: