有一个锚类型=按钮可以吗?

a7o*_*ton 4 html

我尝试过以下方法:

<a href="#" class='aclass'>Fires an event</a> //pops back up to page, not nice
<a href="" class='aclass'>Fires an event</a> //refreshes the page, not nice

<a type="button" class='aclass'>Fires an event</a> //does nothing but the event, good!
Run Code Online (Sandbox Code Playgroud)

只是想知道将带有值按钮的类型属性添加到锚标记在语义上是否可以接受,因为我不记得曾经这样做过,但也许它现在发生并且实际上起作用了。

Mat*_*Cat 5

你想要的不是一个链接而是一个按钮。所以你应该使用

<button type="button" class="aclass">Fires an event</button>
Run Code Online (Sandbox Code Playgroud)

样式设置只是 CSS 的问题。