鼠标悬浮变色,如何让原来有颜色的单元格保持原色

//悬浮

$(".x-table tr").mouseover(function() {

window.color = $(this).find("td").css("background-color");

$(this).find("td").css("background", "red");

});

//离开

$(".x-table tr").mouseout(function() {

$(this).find("td").css("background", color);

});

----------------

如何修改上面的加载结束方法,能实现使原来有颜色的单元格鼠标离开后仍保持原色,而不是变成rgba(0,0,0,0)

xiaoxing2315 发布于 2021-7-19 14:40 (编辑于 2021-7-19 15:37)
1min目标场景问卷 立即参与
回答问题
悬赏:3 F币 + 添加悬赏
提示:增加悬赏、完善问题、追问等操作,可使您的问题被置顶,并向所有关注者发送通知
共7回答
最佳回答
0
杨朝健Lv5中级互助
发布于2021-7-19 17:52(编辑于 2021-7-19 17:55)

//悬浮

$(".x-table tr").mouseover(function() {

  window.color=[];

  $(this).find("td").each(function(){

    window.color.push($(this).css("background-color"));

  });

  $(this).find("td").css("background", "red");

});

//离开

$(".x-table tr").mouseout(function() {

  $(this).find("td").each(function(){

    $(this).css("background", window.color.shift());

  });

});

最佳回答
0
snrtuemcLv8专家互助
发布于2021-7-19 14:50

这个好像比较难取,直接改成报表背景色把,一般是白色,离开后,直接给白色

//离开

$(".x-table tr").mouseout(function() {

$(this).find("td").css("background", "white");

});

最佳回答
0
孤陌Lv6资深互助
发布于2021-7-19 15:41

JS实现分页预览改变鼠标悬停所在的行列的背景色-https://help.fanruan.com/finereport/doc-view-1625.html

最佳回答
0
冥河Lv8初级互助
发布于2021-7-19 15:41

$(".x-table tr[tridx!='0']").mouseout(function(){

    $(this).find("td").css("background",color);

//将当前行下的所有td的背景色变为原色

最佳回答
0
free_zzLv6中级互助
发布于2021-7-19 15:46

我直接用你的好像就是原色,没有变白

移入移出.cpt

最佳回答
0
shirokoLv6资深互助
发布于2021-7-19 15:46

//悬浮

$(".x-table tr").mouseover(function() {

//window.color = $(this).find("td").css("background-color");

$(this).find("td").css("background", "red");

});

//离开

$(".x-table tr").mouseout(function() {

$(this).find("td").css("background", "");

});

   

最佳回答
0
祈LLv6中级互助
发布于2021-7-19 16:50

var $lasttd; //上一个单元格变量

var lastcolor; //上一次颜色变量

$('.x-table tr:gt(0) td') .bind("mousemove", function () {    //鼠标悬浮时

if($lasttd){

$lasttd.parent().find("td").css('background',lastcolor);

} //离开后原单元格恢复原色

lastcolor=$(this).css('background-color');

if(!lastcolor)

lastcolor=$(this).css('background');  //保存原始颜色

$(this).parent().find("td").css('background','yellow'); //设置当前单元格为黄色

$lasttd=$(this);

});

$('.x-table tr:gt(0) td') .bind("mouseout", function () {   //鼠标离开非悬浮时

if($lasttd){

$lasttd.parent().find("td").css('background',lastcolor);}});

可以采纳一下

  • 9关注人数
  • 1242浏览人数
  • 最后回答于:2021-7-19 17:55
    请选择关闭问题的原因
    确定 取消
    返回顶部