繁体   English   中英

jQuery更改TR背景颜色,具体取决于当前选择的文本输入

[英]JQuery Change TR background Colour depending on currently selected Text Input

我正在尝试制作一个更改TR元素的背景颜色的系统,该元素将当前输入框键入到/ Selected中。 我目前拥有它,因此当在当前文本框中输入字母时,您将切换到下一个文本框。

<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>

我希望焦点输入的父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
});

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM