Javascript JQuery根据当前选择的文本输入更改TR背景颜色

Javascript JQuery根据当前选择的文本输入更改TR背景颜色,javascript,jquery,html,css,input,Javascript,Jquery,Html,Css,Input,我试图制作一个系统,改变当前输入框输入/选择的TR元素的背景颜色。我现在有它,所以当在当前文本框中输入一封信时,您可以切换到下一个文本框 <html> <body> <table> <tr> <td> <input type='text' id='txt1' maxlength='1' /> </td>

我试图制作一个系统,改变当前输入框输入/选择的TR元素的背景颜色。我现在有它,所以当在当前文本框中输入一封信时,您可以切换到下一个文本框

<html>

<body>
    <table>
        <tr>
            <td>
                <input type='text' id='txt1' maxlength='1' />
            </td>
        </tr>
        <tr>
            <td>
                <input type='text' id='txt2' maxlength='1[' />
            </td>
        </tr>
    </table>
    <script src="Scouts/resources/plugins/jquery.js"></script>
    <script>
        $('#txt1').keyup(function () {
            if (this.value.length == $(this).attr('maxlength')) {
                $('#txt2').focus();
            }
        });
    </script>
</body>

</html>

$('#txt1').keyup(函数(){
if(this.value.length==$(this.attr('maxlength')){
$('#txt2').focus();
}
});
我希望聚焦输入的父TR元素与其他TR元素的颜色不同。我希望根据重点输入的不同而有所变化

提前谢谢,抱歉我的解释不好

试试看

$('tr input').focus(function () {
    var $tr = $(this).closest('tr'); //get tr
    $tr.css('background-color', 'red'); //change background color 
    $tr.siblings().css('background-color', 'OldColor'); //set sibling tr's background color to be old color
}).blur(function () {
    var $tr = $(this).closest('tr');//get tr
    $tr.css('background-color', 'OldColor');//set tr's background color to be old color
});

@PHP92745382389很高兴它有帮助:)