I have declared asp:textbox in my aspx page.
<asp:TextBox ID="txta" runat="server" size="12" value="123"></asp:TextBox>
and I have a javascript function in HEADER:
<head runat="server">
<title>My Page</title>
<script type = "text/javascript" >
function changeColor() {
document.getElementById('<%= txta.ClientID %>').backgroundColor="#FF0000";
alert( '<%= txta.ClientID %>');
}
</script>
</head>
on Page_Load event I joined onBlur attribute with asp control like this:
txta.Attributes.Add("onblur", "changeColor();")
When control losts focus, alert is shown, but backgroundcolor doesn't changed.
How to achieve this?
Use document.getElementById('<%= txta.ClientID %>').style.backgroundColor = "#FF0000";
.
You forgot the .style
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.