http://jsfiddle.net/7w5Xv/621/

代码HTML:

<div>
    <p>text to appear when the user puts the mouse over</p>
</div>


代码CSS:

    div
{
    background:blue;
    width:100px;
    height:100px;
}

p
{
    display:none;
}


代码JQuery:

  $( 'div' ).hover( function () {

    $( 'p' )//What function should I use here? );

});


我希望该段落仅在用户将箭头放在div上时显示。

我怎么解决这个问题?
你能帮我吗?

提前致谢!

最佳答案

有很多方法可以实现这一目标。请参阅下面的方法。



$(function() {
  var content; // Declare a variable
  content = $('p').text(); // assign the variable to the p's content only

  $('p').text(''); // Leave the content empty by default

  $('p').mouseenter(function() {

    $(this).text(content); // Now show it on mouse enter

  }).mouseleave(function() { // empty on mouse leave
    $(this).text('');
  });
});

p {
  background: blue;
  width: 100px;
  height: 100px;
}

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<p>text to appear when the user puts the mouse over</p>





注意:您可以对DIV而不是P应用相同的方法

关于jquery - jQuery中显示的段落,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/29017052/

10-12 12:28
查看更多