duan1930 2013-08-20 20:28
浏览 39
已采纳

根据div / table中的某些字符应用CSS [关闭]

I have a php function that pulls my csv data and display it as a table on a web page, something very simple!

My question is, is it possible to have a php code or javascript that scans my table td and if the td ends in a certain character/flag/word, then apply a certain CSS to that td?

I want this so I can apply different css images and colors to my td's depending on the character at the end!

  • 写回答

1条回答 默认 最新

  • dpy3846 2013-08-20 21:00
    关注

    This is javascript solution based on last character and test only for two variations, basically it takes last character from table cell text content and checks it against another character. For more options I would use switch.

    http://jsfiddle.net/xqKvp/

    You can change css classes with className property instead of changing inline styles.

    element.className = 'myClass';
    

    There are also numerous options for checking with regular expressions methods or other string object methods, depending on your needs.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大