繁体   English   中英

通过JavaScript更改ASP:TEXTBOX的BackgroundColor

[英]Change BackgroundColor of ASP:TEXTBOX via javascript

我在aspx页面中声明了asp:textbox。

 <asp:TextBox ID="txta" runat="server" size="12" value="123"></asp:TextBox>

而且我在HEADER中有一个javascript函数:

<head runat="server">
<title>My Page</title>

<script type = "text/javascript" >

    function changeColor() {
        document.getElementById('<%= txta.ClientID %>').backgroundColor="#FF0000";
        alert( '<%= txta.ClientID %>');
    }
</script>

</head>

在Page_Load事件中,我使用如下asp控件加入了onBlur属性:

 txta.Attributes.Add("onblur", "changeColor();")

当控件失去焦点时,会显示警报,但背景色不会改变。

如何实现呢?

使用document.getElementById('<%= txta.ClientID %>').style.backgroundColor = "#FF0000";

您忘记了.style

暂无
暂无

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

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