how to change text paragraph(<p>) on mouse over

[亡魂溺海] 提交于 2019-12-11 01:44:44

问题


I have some news links, when user moves on that I have to change text of paragraph containing news in details.


回答1:


It's simple:

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



回答2:


Can you post some example code or what you are working with/what you have so far? Without that, I can only refer you to this page: http://api.jquery.com/mouseover/




回答3:


see solution in action here: http://jsbin.com/asoka4/2

This is a really lazy way to do things =)

<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:


I'm not positive if this is what you're asking, but try using jQuery's .html() method. It sets the innerHTML property for an element, and it'll let you change the text of a <p> element.



来源:https://stackoverflow.com/questions/3087768/how-to-change-text-paragraphp-on-mouse-over

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!