最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Using href attribute for button element - Stack Overflow

programmeradmin1浏览0评论

I need that use href="" attribute for button

like this <button href="link">click me</button> Instead of <a href="link">

that's wrong .

I think that I've to try this code

<button onClick="FN('MY Link For Example www.stackoverflow')" >click me</button>

<script>
function FN('URL'){
     --> Go to MY Link For Example www.stackoverflow
}
<script>

So what do u guys suggest I should do ?

I need that use href="" attribute for button

like this <button href="link">click me</button> Instead of <a href="link">

that's wrong .

I think that I've to try this code

<button onClick="FN('MY Link For Example www.stackoverflow.')" >click me</button>

<script>
function FN('URL'){
     --> Go to MY Link For Example www.stackoverflow.
}
<script>

So what do u guys suggest I should do ?

Share Improve this question edited Jan 21, 2020 at 20:43 isherwood 61.2k16 gold badges122 silver badges170 bronze badges asked May 28, 2015 at 7:38 Danin NaDanin Na 4091 gold badge3 silver badges13 bronze badges 0
Add a ment  | 

4 Answers 4

Reset to default 4

Try this. This will navigate to the link on click.

 <button onclick="window.location.href='http://www.stackoverflow.'">click me</button>

Why you don't use <a type="button" href=""></a>

Or if you really want a button, so <button onclick="window.location.href=""></button>

I think this will solve your problem

<a href="http://www.stackoverflow./">
    <button>click me</button>
</a>

href attribute can not be used on button tag , if you want button like appearance for your a tag you can use add style to your a tag and make it look like button , add bootstrap reference then add button class to your anchor tag. Custom Bootstrap Button , but if you still want to use button tag then adding onclick event is better option

发布评论

评论列表(0)

  1. 暂无评论