0

我们可以为 IE7 等特定浏览器编写事件onbluronfocus

我尝试过的如下。

<asp:TextBox  onfocus="this.style.backgroundColor='yellow'" onblur="this.style.backgroundColor='white'" Text="something" ID="txtName" runat="server" ></asp:TextBox>

请注意,这对我来说很好。但我只需要onbluronfocus在 IE7 上执行。

那可能吗?

也许有人遇到过这种需求。

提前致谢

4

1 回答 1

1

您可以检测浏览器并仅在 IE7 时运行您的脚本

把它放在你的标记正文标签的末尾

<!--[if lte IE 7]>
    <script type="text/javascript">
        var txtBox = document.getElementById('<%= txtName.ClientID %>');
         txtBox.onfocus =function(){ txtBox.style.backgroundColor='yellow';};
         txtBox.onblur=function(){txtBox.style.backgroundColor='white';};
    </script>
<![endif]-->

或者把这个放在头上

<!--[if lte IE 7]>
    <script type="text/javascript">
      window.onload=function(){ 
           var txtBox = document.getElementById('<%= txtName.ClientID %>');
           txtBox.onfocus =function(){ txtBox.style.backgroundColor='yellow';};
           txtBox.onblur=function(){txtBox.style.backgroundColor='white';};
     }
    </script>
<![endif]-->
于 2013-03-24T12:31:15.863 回答