在一個webform中,iam放置了一個文本框,我想在運行時爲該特定文本框選擇一個背景圖像。需要在C#中編寫代碼,.NET .NET在運行時使用c#選擇背景圖像的文本框,asp.net
0
A
回答
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」);。
相關問題
- 1. 在使用jquery的選擇框中使用背景圖像
- 2. 背景圖像選擇
- 3. 編輯運行時asp.net中的列表框選擇的文本
- 4. 如何使背景圖像選擇div?
- 5. 使用javafx在運行時更改背景圖像
- 6. 在ASP.NET C上使用sql填充DropDownList選擇的文本框#
- 7. 文本框背景圖片
- 8. ASP.NET主頁CSS背景圖像邊框
- 9. 在選擇用戶圖像時更改div背景
- 10. 將文本框放在'登錄框'背景圖像
- 11. CSS:選擇TD與背景圖像
- 12. 選擇性地顯示背景圖像
- 13. 在運行時使用c#像腳本
- 14. 變化的背景圖像時復選框被選中
- 15. 使用XML選擇器在背景圖像頂部的Android覆蓋圖像
- 16. 當設置背景圖像時,文本框變得不可見
- 17. 在C運行時未選中複選框時禁用文本框#
- 18. 在背景圖像背景圖像
- 19. pngfix在背景圖像上禁用文本選擇和輸入元素
- 20. 如何使用BMP圖像文件的winform的背景在C#
- 21. ASP.NET Treeview圖像背景
- 22. 背景顏色背景圖像之間的圖層文本
- 23. 刪除鍵入文本時的文本框的背景圖像。怎麼樣?
- 24. 將背景圖像放在文本上?
- 25. Android ListView選擇器同時更改背景圖像和文本顏色
- 26. 如何在運行時更改按鈕的背景圖像?
- 27. 在運行時刪除UIImageView中的圖像背景
- 28. 如何在iPhone運行時刪除圖像的背景sdk
- 29. C#圖像選擇框
- 30. 如何在圖像有圖標時使背景圖像不干擾文本