如何使(链接)按钮具有超链接的功能? [英] How to make (link)button function as hyperlink?

查看:34
本文介绍了如何使(链接)按钮具有超链接的功能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何使用 asp:Buttonasp:LinkBut​​ton 作为 asp:Hyperlink?

How do I use an asp:Button or asp:LinkButton as asp:Hyperlink?

现有的超链接只是转到同一页面上的另一个部分: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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆