2010-02-04 121 views
0

的名字,我有以下链接更改HREF链接

<a href="example.com" id="example1"> Go to example....</a> 

是否有可能,当身体在将光标移到“转到例子......”它改变为“转到例如一个”我使用PHP和jQuery。任何帮助将不胜感激。使用jQuery

回答

1

.hover()助手在这里很有用,以防止恼人的事件冒泡:

var elem = $('#examle1'), orig = elem.text(); 
elem.hover(
    function() { $(this).text('Go to example One'); }, 
    function() { $(this).text(orig); } 
); 
3

应该不会太困难:

$('#example1') 
    .mouseover(function(e) { $(this).text('Go to example One') }) 
    .mouseout(function(e) { $(this).text('Go to example...') }); 

删除第二个绑定,如果你不需要它回去“......”当用户移动鼠标了。

编辑:忘了鼠标悬停helper方法

3

尝试了这一点..

$('#example1').mouseover(function() { 
    $(this).text('Go to example One'); 
}); 

雅错过我是想快速得到#;)

+0

因为它是你必须使用#在例1 – rahul 2010-02-04 09:41:16

3
$(function(){ 
    $("#example1").mouseover(function(){ 
     $(this).text('Go to example One'); 
    }); 
}); 

或者您可以使用hover功能如

$(function(){ 
    $("#example1").hover(
     function() { 
     $(this).text('Go to example one'); 
     }, 
     function() { 
     $(this).text('Go to example....'); 
     } 
    ); 
}); 
+1

前一个ID选择+ 1:我更喜欢将hover()放在我的方法 – 2010-02-04 10:40:38

0

这里是PHP代码

<span 
class="trackTitle"> <a href="<?php print "play/".$link;?>" title="Listen or Download <?php echo $hoverActual ?>" onmouseover="javascript:changeTo('<?php echo $hoverActual; ?>');"><?php echo $fileName; ?></a></span> 

在功能changeTo时,我想改变$文件名; 。

+0

使用像'onmouseover'这样的事件属性被认为是不好的做法。 – 2010-02-04 09:53:06

1

你甚至可以做到这一点与CSS只。你只需要在您的链接两个元素就可以解决这样的:

<a href="example.com" id="example1"> Go to example <em>…</em> <span>One</span></a> 

和相应的CSS行为:

a span, 
a:hover em { 
    display: none; 
} 
a:hover span { 
    display: inline; 
}