如何使(链接)按钮功能作为超链接? [英] How to make (link)button function as hyperlink?
本文介绍了如何使(链接)按钮功能作为超链接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何使用 asp:Button
或 asp:LinkButton
as asp:超链接
?
现有的超链接只是转到同一页面上的另一个部分: NavigateUrl =#Section2
The existing Hyperlink just goes to another section on the same page: NavigateUrl="#Section2"
我想在aspx文件中执行此操作而无需额外编码。谢谢。
I want to do this in the aspx file without additional coding. Thanks.
目的是让按钮看起来而不是带下划线的文字但是我不想使用带超链接的图像来实现此目的。
The purpose is to have a button look instead of the underlined text BUT I don't want to use an image with hyperlink to achieve this purpose.
推荐答案
您可以使用OnClientClick事件来调用JavaScript函数:
You can use OnClientClick event to call a JavaScript function:
<asp:Button ID="Button1" runat="server" Text="Button" onclientclick='redirect()' />
JavaScript代码:
JavaScript code:
function redirect() {
location.href = 'page.aspx';
}
但我认为最好用css设置超链接样式。
But i think the best would be to style a hyperlink with css.
示例:
.button {
display: block;
height: 25px;
background: #f1f1f1;
padding: 10px;
text-align: center;
border-radius: 5px;
border: 1px solid #e1e1e2;
color: #000;
font-weight: bold;
}
这篇关于如何使(链接)按钮功能作为超链接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文