如何将图像制作为按钮并将其重定向到另一个页面

How to make an image as a button and redirect it to another page?

本文关键字:重定向 另一个 按钮 图像      更新时间:2023-09-26
<asp:ImageButton ID="imgbtn_RoleGuideWin8" runat="server"  ImageUrl="~/Images/Windows Logo.png" Width="215px" OnClick="imgbtn_RoleGuideWeb_Click" OnClientClick="fnOnWin8ButtonClick()" />

我有使用 asp.net 的代码,我想将其转换为 HTML。为此,我编写了以下代码:

<input type="image" src="/Images/Windows Logo.png" id="myButton" />
<script type="text/javascript">
document.getElementById("myButton").onclick = function () {
location.href = "www.google.com";
};
</script>

但这行不通。有朋克吗?

#myButton{
  border-radius: 15px;
  border: 1px solid gray;
  display: inline-block;
  padding: 10px 15px;
  }
#myButton img{
    display:block;
    width: 200px;
  }
#myButton:hover{
  background: wheat;
  }
<a href="#" onclick="javascript:location.href='http://www.google.com';" id="myButton">
        <img src="https://www.google.com/images/srpr/logo11w.png" alt="you should use alt tags" />
    </a>

请注意,我将您的 ID 移到了 <a> 标签上,以便您可以根据需要设置其样式,使其看起来像一个按钮

<form name="test" method="post" action="http://www.example.com">
  <input id="tst" type="submit"/>
  </form>
然后在 css 文件中,您应该使用以下代码:

#tst
{
background-image:url("https://www.google.com/images/srpr/logo11w.png");//or other urls.
}