jq点击行:行变颜色,字体也变颜色

但我现在的问题是,行变颜色没有问题,字体变颜色是成功了,但是当我点击别的行的字体颜色变不回去啦,这个jq应该怎么改哈

var obj = $("tr.tntr>td span");

var objj = $("tr.tntr");

objj.click(function(){

$(this).find('span').css("color","#4DA1FF").siblings().css("color",'#000');   --字体

$(this).css("background-color","#edf5ff").siblings().css("background-color","#ffffff"); --一行

});

image.png

yikefu 发布于 2022-3-18 15:02
1min目标场景问卷 立即参与
回答问题
悬赏:4 F币 + 添加悬赏
提示:增加悬赏、完善问题、追问等操作,可使您的问题被置顶,并向所有关注者发送通知
共2回答
最佳回答
0
luojian0323Lv7资深互助
发布于2022-3-18 15:13(编辑于 2022-3-18 15:14)

我给你个例子,你改一下,这个是鼠标划入和移出的例子(只有行变色,没有字体变色哦,但可以实现鼠标移出,恢复原色) var color=""

 $(".x-table tr").mousemove(function() {//鼠标划入事件     

    if (this.id !== 'r-0-0') { //排除标题行        

     $(this).children("td").each(function() {//遍历单元格        

     color=$(this).css("background-color")         

    $(this).css("background-color", 'rgb(255, 255,0)');})}});//添加背景色

$(".x-table tr").mouseout(function() {//鼠标移出事件     

    if (this.id !== 'r-0-0') {//排除标题行            

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

    $(this).css("background-color", color);});           

  }         

});

最佳回答
0
15922204585Lv6高级互助
发布于2022-3-23 20:43(编辑于 2022-3-23 20:45)

var $lasttd;

var lastcolor;

var color

$('.x-table tr:gt(0) td') .bind("mousedown", function () {

if($lasttd){

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

}

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

color=$(this).css('color');

if(!lastcolor)

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

$(this).parent().find("td").css('background','yellow').css('color','red');

$lasttd=$(this);

});

image.png

mouseenter:悬浮

  • 3关注人数
  • 409浏览人数
  • 最后回答于:2022-3-23 20:45
    请选择关闭问题的原因
    确定 取消
    返回顶部