【问题标题】:how to change text paragraph(<p>) on mouse over如何在鼠标悬停时更改文本段落(<p>)
【发布时间】:2010-06-21 19:21:43
【问题描述】:

我有一些新闻链接,当用户继续前进时,我必须更改包含详细新闻的段落文本。

【问题讨论】:

    标签: jquery onmouseover


    【解决方案1】:

    很简单:

    $('a.newslink').bind('mouseover', function() {
       $('p#newsdetail').text('new text');
    })
    

    【讨论】:

    • 这是一个字符串,随便你。例如,详细的新闻。
    【解决方案2】:

    您能否发布一些示例代码或您正在使用的/目前拥有的内容?没有那个,我只能推荐你到这个页面:http://api.jquery.com/mouseover/

    【讨论】:

    • 我怀疑该链接中的 mouseenter 和 leave 示例是 nectar 想要的。
    【解决方案3】:

    在此处查看实际解决方案:http://jsbin.com/asoka4/2

    这是一种非常懒惰的做事方式=)

    <script type='text/javascript'>
    $( function() {
      $("#news li").hover(
        function () {
          $(this).attr('small',$(this).html());
          $(this).html($(this).attr('full'));
        },
        function () {
           $(this).html($(this).attr('small'));
        }
      );
    });
    </script>
    
      <ul id='news'>
        <li id='news1' full='<strong>this is the full news 1</strong>'>This is some news 1</li>
        <li id='news2' full='<del>This is the full news 2</del>'>This is some news 2</li>
        <li id='news2' full='<a href="http://www.google.com">Check google.com for this one!'>This is some news 3</li>
      </ul>
    

    【讨论】:

      【解决方案4】:

      如果这是您的要求,我不肯定,但请尝试使用 jQuery 的 .html() method。它为元素设置innerHTML 属性,并允许您更改&lt;p&gt; 元素的文本。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2019-03-07
        • 2012-02-10
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-12-05
        相关资源
        最近更新 更多