【发布时间】:2014-04-07 19:03:53
【问题描述】:
我正在创建一个引用图像的 ImageButton,其中包含多个图标。我试图通过定位背景图像来显示正确的图标,但这不起作用。这是我创建ImageButton的方法:
ImageButton closeButton = new ImageButton();
closeButton.CommandName = "CloseItem";
closeButton.ID = "BtnClose";
closeButton.Width = 16;
closeButton.Height = 16;
closeButton.ImageUrl = "/_layouts/15/1031/images/formatmap16x16.png?rev=23.gif";
closeButton.Style.Add(HtmlTextWriterStyle.Top, "-115");
closeButton.Style.Add(HtmlTextWriterStyle.Left, "-275");
closeButton.OnClientClick = btn.OnClientClick;
this.Controls.Add(closeButton);
这会产生以下 HTML:
<input type="image"
name="ctl00$ctl40$g_8cd9fd5c_6191_46af_bf6a_ac27c5fb0e80$ctl00$toolBarTbl$RightRptControls$ctl02$BtnClose"
id="ctl00_ctl40_g_8cd9fd5c_6191_46af_bf6a_ac27c5fb0e80_ctl00_toolBarTbl_RightRptControls_ctl02_BtnClose"
src="/_layouts/15/1031/images/formatmap16x16.png?rev=23.gif"
onclick="STSNavigate('http:\u002f\u002fespseis13\u002fsharechange\u002fdefault.aspx');return false;WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions("ctl00$ctl40$g_8cd9fd5c_6191_46af_bf6a_ac27c5fb0e80$ctl00$toolBarTbl$RightRptControls$ctl02$BtnClose", "", true, "", "", false, false))"
style="height:16px;width:16px;top: -115px;left: -275px">
我正在显示的图像是这个:
我不能轻易切换输入类型,因为它需要属性CommandName = "CloseItem"。
有谁知道,我如何移动(而不是缩放!)由 image 类型的 input 引用的图像?
【问题讨论】:
-
我认为你不能为
input[type = image]使用精灵,可以吗? -
伙计,那会很糟糕:(
-
是的:"一个图形提交按钮。您必须使用 src 属性来定义图像的来源,并使用 alt 属性来定义替代文本。您可以使用 height 和 width 属性来以像素为单位定义图像的大小。” developer.mozilla.org/en-US/docs/Web/HTML/Element/Input
标签: html asp.net css sharepoint-2013 html-input