2009-12-12 37 views

回答

0

你可以使用css來設置背景圖片和javascript來改變它。這裏有一個例子:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="ToDDDD._Default" %> 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 

<html xmlns="http://www.w3.org/1999/xhtml" > 
<head runat="server"> 
    <title></title> 
    <style type="text/css"> 
    input 
    { 
     background-image: url(/initialImage.png) 
    } 
    </style> 
    <script type="text/javascript"> 
     function changeImage() { 
      document.getElementById('txt').style.backgroundImage = 'url(/newImage.png)'; 
     } 
    </script> 
</head> 
<body> 
    <form id="form1" runat="server"> 
    <div> 
     <asp:TextBox ID="txt" runat="server" /> 
     <a href="#" onclick="changeImage();">Change background image</a> 
    </div> 
    </form> 
</body> 
</html> 
0

如果你要使用的背景圖片的數量有限,那麼它很可能是乾淨的在你的CSS,然後編程或者與他們每個人的定義爲一個單獨的類JavaScript或C#更改輸入上的類。

<style> 
.image1 { background-image: url(/image1.png);} 
.image2 { background-image: url(/image2.png);} 
.image3 { background-image: url(/image3.png);} 
</style> 

在你的Page_Load你網頁的你就可以這樣寫:

txtBox1.CssClass = 「此搜索」;

或者使用javascript:

的document.getElementById( '<%= txtBox1.ClientID%>')的setAttribute( 「類」, 「圖像2」);。