简体   繁体   中英

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

<asp:ImageButton ID="imgbtn_RoleGuideWin8" runat="server"  ImageUrl="~/Images/Windows Logo.png" Width="215px" OnClick="imgbtn_RoleGuideWeb_Click" OnClientClick="fnOnWin8ButtonClick()" />

I have this code using asp.net.I want to convert it to HTML. For doing that I have written this code:

<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>

But this is not working. Any poninters?

 #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> 

Note that I moved your ID to the <a> tag so you can style that as you wish to make it look like a button

 <form name="test" method="post" action="http://www.example.com"> <input id="tst" type="submit"/> </form> 
Then in css file, you should use this code:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM