每当关注“输入"时更改"tr"样式? [英] changing `tr` style whenever an `input` was focused?

查看:89
本文介绍了每当关注“输入"时更改"tr"样式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下html:

<table id="TableNewUser" runat="server" width="50%" cellpadding="3" cellspacing="1"
border="0">
<tr>
    <th colspan="2">
        New User
    </th>
</tr>
<tr>
    <td width="50%" align="right">
        <asp:TextBox ID="TextBoxUsername" runat="server" Style="direction: rtl;" MaxLength="25"></asp:TextBox>
    </td>
    <td align="left" width="50%">
        UserName
    </td>
</tr>
<tr>
    <td align="right">
        <asp:TextBox ID="TextBoxPass" runat="server" MaxLength="25"></asp:TextBox>
    </td>
    <td align="left">
        Password :
    </td>
</tr>
<tr>
    <td colspan="2">
        <asp:Button ID="ButtonSubmit" runat="server" Text="Submit" OnClick="ButtonSubmitClick" />
    </td>
</tr>
</table>

每当文本框被聚焦时,我都想更改tr样式.
我已经在CSS代码下面使用了,但是它不起作用.

I wanna change the tr style whenever the text-boxes are focused.
I've used below CSS code but it doesn't work.

input[type="text"]:focus tr
{
    background-color: #e7e7e7;
}

你能指导我吗?

推荐答案

正如Dissappointment先生所述,您必须使用JavaScript(或jquery)来实现所需的功能.

As Mr. Dissappointment stated, you must use JavaScript (or jquery) to achieve what you want.

我编写了一个非常简单的HTML页面进行示例:

I coded a very simple HTML page to exemplify:

<html>
<head>
<script type="text/javascript">
function changeTrStyle()
{
document.getElementById("trId").style.background = "red";
}
</script>
</head>
<body>
<table>
    <tr id="trId">
        <td>
            <input type="text" onfocus="changeTrStyle()"/>
        </td>
    </tr>
</table>
</body>
</html>

如果将焦点放在文本框中, tr 背景将变为红色.

If you focus the textbox, the tr background will become red.

注意:已在Safari和Chrome上进行了测试.

Note: Tested on Safari and Chrome.

这篇关于每当关注“输入"时更改"tr"样式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆