2010-02-04 197 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; 
}