我有一个显示如下计数的div:
如何将文本从0更改为任何单词,例如,当鼠标位于div上时,并在鼠标离开时恢复为0.
我尝试了这段代码,但它没有用.
$('.post-fav a').bind('mouseenter',function() {
var default_text = $(this).text();
$(this).css({'background-position' : 'left bottom', 'color' : '#1871a4'});
$(this).html('<?php _e('favorite','deluxe'); ?>');
});
$('.post-fav a').bind('mouseleave',function() {
$(this).css({'background-position' : 'left top', 'color' : '#666'});
$(this).text(default_text);
});
Run Code Online (Sandbox Code Playgroud)
默认文本是可变的,每个元素都有特定的计数,我需要在鼠标移动时存储初始计数.我不能在js中将其硬编码为0或任何其他计数.
你只需要使用悬停功能,第一个参数是mouseover,第二个是mouseout:
$('div').hover(
function() { $(this).html('anyword'); },
function() { $(this).html('0'); }
);
Run Code Online (Sandbox Code Playgroud)
编辑:
var storedtext;
$('div').hover(
function() {
storedtext = $(this).html();
$(this).html('anyword');
},
function() { $(this).html(storedtext); }
);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1636 次 |
| 最近记录: |