问题
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