使用pug.js在<a> </a>标记内放置一个按钮

Alv*_*Lau -1 html node.js pug

这是我的预期结果:

<a>
    <button class="btn btn-tomato mx-auto" type="button" style="width:50%; white-space: normal; opacity:0.8;">Button text</button>  
</a>
Run Code Online (Sandbox Code Playgroud)

所以我这样写我的哈巴狗:

a
    button.btn.btn-tomato.mx-auto(type='button', style='width:50%; white-space: normal; opacity:0.8')
Run Code Online (Sandbox Code Playgroud)

但是,结果是这样的:

<a></a>
<button class="btn btn-tomato mx-auto" type="button" style="width:50%; white-space: normal; opacity:0.8;">Button text</button>
Run Code Online (Sandbox Code Playgroud)

<button>在不<a>。你能告诉我如何解决吗?谢谢。

Que*_*tin 6

HTML 禁止按钮出现在锚点内。

  • 如果需要链接,请使用<a>

  • 如果要提交表单,请使用<button>

  • 如果您想要某种东西来触发JavaScript并且不能编写Unobtrusive JS,请使用<button type="button">

然后应用CSS使其看起来像您想要的样子。