2011-04-14 35 views
1

我有以下的html:每当“输入”被聚焦时,改变`tr`风格?

<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代码,但它不起作用。

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

你能指导我吗?

+0

http://jquery.com/ – 2011-04-14 20:53:50

+0

这是为什么downvoted?看起来像一个有效的问题。 – rockerest 2011-04-14 21:24:03

+0

Upvoted因为这似乎是一个有效的问题,没有人给它一个downvoted的理由。 – 2011-04-14 21:26:36

回答

2

正如Mr. Dissappointment所述,您必须使用JavaScript(或jquery)来实现您想要的功能。

我编写了一个非常简单的HTML页面来举例说明:

<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背景将变成红色。

注:在Safari和Chrome上测试。