根据单元格中的值选择表格单元格 [英] Select table cells based on the value in the cell

查看:147
本文介绍了根据单元格中的值选择表格单元格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个表,如 http://jsfiddle.net/Lijo/UqdQp/4 /.我需要将所有值为"1"的列的背景色设置为红色.使用jQuery执行此操作的最佳方法是什么(就性能而言)?

I have a table as shown in http://jsfiddle.net/Lijo/UqdQp/4/. I need to set background color as red for all columns that has value "1". What is the best way (in terms of performance) for doing this using jQuery?

注意:做完背景色后,我还需要提醒表格单元格的值.这意味着我需要在选定的单元格上使用"this"运算符.

Note: After doing the background color, I need to alert the value of the table cell also. That means I need to use "this" operator on the selected cell.

参考答案:

  1. http://jsfiddle.net/Lijo/uGKHB/11/
  2. http://jsfiddle.net/Lijo/uGKHB/12/
  3. 在表时使用jQuery查找列索引包含跨列单元格
  1. http://jsfiddle.net/Lijo/uGKHB/11/
  2. http://jsfiddle.net/Lijo/uGKHB/12/
  3. Finding column index using jQuery when table contains column-spanning cells

推荐答案

var $tds = $("td").filter(function(i){
    return $(this).html() == 1;
});

$tds.css({ background: 'red' });

$.each($tds, function(i, x){
    console.log($(x).html());
});

出于明显的原因,我使用console.log代替了警报.

I used console.log instead of alert for obvious reasons.

这篇关于根据单元格中的值选择表格单元格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆