jQuery找到相同的td在prev。和下一行 [英] jQuery find same td in prev. and next row
本文介绍了jQuery找到相同的td在prev。和下一行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个表,我知道如何搜索下一个<上一页 TD
,但如何做到下一个和上一页。 TR
?
i have a table and i know how to search next and prev TD
, but how to do it on the next and prev. TR
?
012
345 <- example, i clicked on 4, it checks 3 and 5, but how to check on 0,1,2 and 6,7,8?
678
$(document).ready(function() {
$("td").click(function() {
var x = $(this).next().css('backgroundColor');
var y = $(this).prev().css('backgroundColor');
if (x == 'rgb(255, 0, 0)' || y == 'rgb(255, 0, 0)') {
return;
} else {
$(this).css('backgroundColor', 'red');
}
});
});
推荐答案
我进行了一些研究,这样可行。感谢所有人的帮助:
I made some research and came up with a working solution that works. Thanks all for help:
$(this).parent().next().find('td').eq($(this).index()-1).css('backgroundColor');
这篇关于jQuery找到相同的td在prev。和下一行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文