C# 我可以在 ASP:Button 的 Text 属性中放置一个 <span> 标签吗?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/611449/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Can I put a <span> tag in the Text property of an ASP:Button?
提问by Xaisoft
I am trying to do something like this:
我正在尝试做这样的事情:
<asp:Button ID="btnSearch"
runat="server"
CssClass="greybtn"
Text='<span>Search</span>'
OnClick="btnSearch_Click" />
It displays <span>Search</span>
instead of just Search
.
它显示<span>Search</span>
而不仅仅是Search
.
采纳答案by Rex M
You can't put markup inside a button. An asp:Button control just renders as an input button HTML tag: <input type="button" value="<span>Search</span>" />
(technically value="<span>Search</span>" />
). The browser treats the contents of the value
attribute as a literal string.
您不能在按钮内放置标记。asp:Button 控件只是呈现为输入按钮 HTML 标记:(<input type="button" value="<span>Search</span>" />
技术上value="<span>Search</span>" />
)。浏览器将value
属性的内容视为文字字符串。
However, you canput markup inside a <button><span>Search</span></button>
(you can put quite a bit of HTML in there, including images). This questiontalks about building a control which emits the button
tag.
但是,您可以在 a 中放置标记<button><span>Search</span></button>
(您可以在其中放置相当多的 HTML,包括图像)。这个问题讨论了构建一个发出button
标签的控件。
回答by Pawel Krakowiak
No. It renders a tag, so whatever you put in the Text property gets rendered as that button's value.
不。它呈现一个标签,所以你在 Text 属性中放置的任何内容都会呈现为该按钮的值。
回答by Joel Coehoorn
The text property will automatically turn <
and >
into the entities <
and >
. More than that, button renders to html as an input
element, with the text set in it's value
property.
text 属性会自动变成<
和>
变成实体<
和>
。更重要的是,按钮呈现为 html 作为input
元素,并在其value
属性中设置文本。
Do you maybe want a HyperLink or Label control instead?
您可能想要一个 HyperLink 或 Label 控件吗?
回答by Rasith
You can have a asp linkButton for this:
您可以为此使用一个 asp linkButton:
回答by Philip Johnson
You can put a span on an ASP.NET LinkButton like this:-
您可以像这样在 ASP.NET LinkButton 上放置一个跨度:-
<asp:LinkButton ID="TestLinkButton" CssClass="btn btn-success" runat="server"><span class="glyphicon glyphicon-refresh"/>Press Me</asp:LinkButton>