【发布时间】:2011-01-13 00:05:00
【问题描述】:
我有以下链接
<a href="example.com" id="example1"> Go to example....</a>
是否有可能当正文将光标移到“转到示例...”上时,它会更改为“转到示例一”,我正在使用 php 和 jquery。任何帮助将不胜感激。
【问题讨论】:
我有以下链接
<a href="example.com" id="example1"> Go to example....</a>
是否有可能当正文将光标移到“转到示例...”上时,它会更改为“转到示例一”,我正在使用 php 和 jquery。任何帮助将不胜感激。
【问题讨论】:
使用 jQuery 应该不会太难:
$('#example1')
.mouseover(function(e) { $(this).text('Go to example One') })
.mouseout(function(e) { $(this).text('Go to example...') });
如果您不需要在用户将鼠标移开时返回“...”,则删除第二个绑定。
编辑:忘记了鼠标悬停辅助方法
【讨论】:
试试这个..
$('#example1').mouseover(function() {
$(this).text('Go to example One');
});
你错过了我试图快速进入的# ;)
【讨论】:
$(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....');
}
);
});
【讨论】:
这里是 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; .
【讨论】:
onmouseover这样的事件属性被认为是不好的做法。
.hover() 助手在这里很有用,可以防止烦人的事件冒泡:
var elem = $('#examle1'), orig = elem.text();
elem.hover(
function() { $(this).text('Go to example One'); },
function() { $(this).text(orig); }
);
【讨论】:
您甚至可以仅使用 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;
}
【讨论】: