Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/41.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何选择直到";这";使用Jquery(或CSS5)_Jquery_Css_Select - Fatal编程技术网

如何选择直到";这";使用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');
    }
);