0

我有带有背景图像的文本框。每当我单击文本框时,背景图像应该会消失,并且只有文本应该可见。当文本被清除后,bg 图像应该会再次出现。这怎么可能 ?

<asp:TextBox runat="server"  Width="160px" ID="txt_google_search" style="padding: 6px; background: url('http://www.google.com/cse/intl/en/images/google_custom_search_watermark.gif') no-repeat scroll left center rgb(255, 255, 255);" ></asp:TextBox>

我在我的代码隐藏中尝试了以下内容,但它不起作用。

txt_google_search.Attributes.Add("onclick", "me.style.backgroundImage = none;")
4

1 回答 1

0

归根结底,这只是客户端 OnClick 事件的错误代码。我会为此使用 jQuery,并生成如下内容:

<style>
.bgImage {
    background: url(img/sprite.gif) no-repeat left top;
}
</style>

<script>
$(function(){
   $("#<% Response.Write(txt_google_search.ClientId) %>").live("focus", function() { 
      $("#<% Response.Write(txt_google_search.ClientId) %>").addClass("bgImage");
  });
   $("#<% Response.Write(txt_google_search.ClientId) %>").live("blur", function() { 
      $("#<% Response.Write(txt_google_search.ClientId) %>").removeClass("bgImage");
  });
});
</script>
于 2013-01-18T07:21:03.430 回答