0

我有以下链接

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

是否有可能当正文将光标移到“转到示例...”上时,它会更改为“转到示例 One”,我正在使用 php 和 jquery。任何帮助将不胜感激。

4

6 回答 6

3

使用 jQuery 应该不会太难:

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

如果您不需要在用户将鼠标移开时返回“...”,请删除第二个绑定。

编辑:忘记了 mouseover 辅助方法

于 2010-02-04T09:40:09.993 回答
3

试试这个。。

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

雅错过了我试图快速进入的# ;)

于 2010-02-04T09:40:35.437 回答
3
$(function(){
    $("#example1").mouseover(function(){
        $(this).text('Go to example One');
    });
});

或者您可以使用悬停功能,例如

$(function(){
    $("#example1").hover(
      function () {
        $(this).text('Go to example one');
      }, 
      function () {
        $(this).text('Go to example....');
      }
    );
});
于 2010-02-04T09:40:45.333 回答
1

帮助器在.hover()这里很有用,可以防止烦人的事件冒泡:

var elem = $('#examle1'), orig = elem.text();
elem.hover(
    function() { $(this).text('Go to example One'); },
    function() { $(this).text(orig); }
);
于 2010-02-04T09:49:21.517 回答
1

你甚至可以只用 CSS 来做到这一点。您只需要链接中的两个元素即可解决,例如:

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

以及相应的 CSS 行为:

a span,
a:hover em {
    display: none;
}
a:hover span {
    display: inline;
}
于 2010-02-04T09:53:04.270 回答
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 的地方,我想更改 $fileName; .

于 2010-02-04T09:48:41.953 回答