使用鼠标悬停上的jquery隐藏特定文本
我似乎无法让它工作:使用鼠标悬停上的jquery隐藏特定文本,jquery,html,css,mouseover,Jquery,Html,Css,Mouseover,我似乎无法让它工作: $('.products-grid li').hover( function(){ $('.price').html().replace('DKK',''); }); 我希望鼠标悬停在列表项上时,“DKK”不会显示。 我知道我可以通过在DKK周围增加一个跨度来实现这一点,但我不可能这样做。我被锁定在HTML的设置中,正如您在这里看到的那样 希望有人能帮助我。 这可能是我缺少的一个简单的jQuery编码,但我不能完全理解。设置脚本中元素的html。当前脚本只修改.
$('.products-grid li').hover(
function(){
$('.price').html().replace('DKK','');
});
我希望鼠标悬停在列表项上时,“DKK”不会显示。
我知道我可以通过在DKK周围增加一个跨度来实现这一点,但我不可能这样做。我被锁定在HTML的设置中,正如您在这里看到的那样
希望有人能帮助我。
这可能是我缺少的一个简单的jQuery编码,但我不能完全理解。设置脚本中元素的
html
。当前脚本只修改.price
的innerHtml,它没有设置price的html
$('.products-grid li').hover(
function(){
$('.price').html($('.price').html().replace('DKK',''));
});
工作示例:以下是提示的小代码:
abcd xyz <label class='txt'>DDK</label>dbs ksbdh ksjdk <label class='txt'>DDK</label>
您需要调用.html()两次,一次用于获取字符串,一次用于设置字符串
您的代码$('.price').html().replace('DKK','')
正在获取每个.price
元素上的文本,替换文本并将其返回为空
要在您离开元素时恢复DKK,您可以这样做,您还需要以
.price
而不是li
为目标
$('.products-grid li').mouseover(function(){
$('.price').each(function(){
var replaced = $(this).html().replace('DKK','');
$(this).html(replaced);
});
}))当我离开列表项时,我如何找回DKK?更新后,它们现在不会改变。需要使用
$。每个
或用于
。更接近-现在它只需处理一个列表项,而不是一次处理所有项。:)明白我的意思吗?更新后,我们的目标是.price
而不是li
。如果您将鼠标悬停在DKK上,您会注意到一些闪烁,您可以通过设置.price{display:block;}
来解决此问题,正如我所说的-我不能这样做。
$('.products-grid li').hover(function () {
$('.price').html($('.price').html().replace('DKK', ''));
});
$('.products-grid .price').hover(function () {
$(this).each(function () {
var me = $(this);
me.html(me.html().replace('DKK', ''));
});
}, function () {
$(this).each(function () {
var me = $(this);
me.html(me.html() + 'DKK');
});
});
$('.products-grid li').mouseover(function(){
$('.price').each(function(){
var replaced = $(this).html().replace('DKK','');
$(this).html(replaced);
});