如何选择直到";这";使用Jquery(或CSS5)
假设我有一张这样的桌子:如何选择直到";这";使用Jquery(或CSS5),jquery,css,select,Jquery,Css,Select,假设我有一张这样的桌子: <table> <tbody id="example"> <tr> <td>cell-1</td> <td>cell-2</td> <td>cell-3</td> <td>cell-4</td> </
<table>
<tbody id="example">
<tr>
<td>cell-1</td>
<td>cell-2</td>
<td>cell-3</td>
<td>cell-4</td>
</tr>
</tbody>
</table>
或者,CSS5是否可能实现这一点?请尝试以下操作:
$('tr > td','#example').mouseover(function(e) {
// Remove .selected from All <td />
$('tr > td','#example').removeClass('selected');
// Look Through All <td /> Until Reaching Current
var el = $(this).get(0);
$('tr > td','#example').each(function(){
$(this).addClass('selected');
if ($(this).get(0) == el){
return false;
}
});
});
编辑演示
我希望这有帮助 很好的问题,但是你错过了最重要的细节。。使用此选择代码,您试图实现什么目标?(只是jQuery、更改CSS等)我不明白你的问题?我想在Jquery或CSSTell me中“选择直到这个”:什么是CSS5?
$('tr > td','#example').mouseover(function(e) {
// Remove .selected from All <td />
$('tr > td','#example').removeClass('selected');
// Look Through All <td /> Until Reaching Current
var el = $(this).get(0);
$('tr > td','#example').each(function(){
$(this).addClass('selected');
if ($(this).get(0) == el){
return false;
}
});
});
$('tr > td','#example').hover(
function (){
var elIndex = $('tr > td','#example').index(this);
elIndex += 1; // To Include Current Element
$('tr > td','#example').slice(0, elIndex).addClass('selected');
},
function (){
$('tr > td','#example').removeClass('selected');
}
);