简体   繁体   English

我如何有一个输入按钮和<a>标签?</a>

[英]How do I have an input button and <a> tag?

I have this: 我有这个:

<a>
Stuff stuff stuff
<input type="Submit" onclick="....">
</a>

The problem is...when I click the submit button, it goes to the instead of onclick. 问题是...当我单击提交按钮时,它将转到onclick而不是onclick。

Try this: 尝试这个:

<input type="Button" onclick="....">

Use Button type instead of Submit :) 使用Button类型,而不是Submit :)

If you still want to use Submit , just place return false after your code eg: 如果仍然要使用Submit ,只需在代码后放置return false ,例如:

<input type="Submit" onclick="doStuff(); return false;">

Returning false from you on click handler should prevent the default behaviour, eg: 在点击处理程序上向您返回false会阻止默认行为,例如:

<a href="index.html">
  Stuff stuff stuff
  <input type="Submit" onclick="alert('test'); return false;">
</a>

您还可以使用CSS display: blockdisplay: inline-block使<a>看起来像按钮

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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