简体   繁体   English

如何在标签href内添加按钮

[英]How to add button inside a tag href

I wanted to have tag with href and image inside, i have added some css and my tag looks like a square with href link, and now i want to add clickable button inside tag, button with javascript onClick.我想在里面添加带有 href 和图像的标签,我添加了一些 css,我的标签看起来像一个带有 href 链接的正方形,现在我想在标签内添加可点击的按钮,带有 javascript onClick 的按钮。 I have add it but when i'm clicking button href link clicked not my js function, anybody can help me with this?我已经添加了它,但是当我单击按钮 href 链接时单击的不是我的 js 函数,有人可以帮我解决这个问题吗?

a tag is the only element that can have an attribute of href . a标签是一个可以具有的属性的唯一元件href I've made a small sample:我做了一个小样本:

HTML: HTML:

<a href="#">Click me</a>


CSS: CSS:

a {
  display: block;
  padding: 10px 0;
  background: red;
  text-decoration: none;
  text-align: center;
  color: #fff;
  font: 17px Arial;
}

But for the onClick event, how would you like it to be executed?但是对于onClick事件,您希望它如何执行?

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

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