我正在尝试制作一个系统来更改 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
});
关于javascript - JQuery 根据当前选择的文本输入更改 TR 背景颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22581091/