<a> onclick not clickable without href

时间:2018-05-02 09:34:29

标签: html

  <a class="btn2" onclick="alertbox()">link </a>  
    <script> 
    function alertbox()  {
       alert("alert box"); 
    } 
    </script>

I have tried to use the css below to try and fix it but that does not make it clickable it only changes the cursor

    .btn2 {
        cursor: pointer; 
    }  

but that only changes the cursor when i hover over it and dont make it actually clickable

sorry if really obvious answer only recently i started to do html

2 个答案:

答案 0 :(得分:1)

<a>添加一些文字并且有效:

&#13;
&#13;
.btn2 {
cursor: pointer; 
}
&#13;
<a class="btn2" onclick=alertbox();>Link</a>  
<script> 
  function alertbox()  {
        alert("alert box")}
</script>
&#13;
&#13;
&#13;

答案 1 :(得分:0)

你错过了&gt;在锚标签中 和你的功能结束时的一个}

 <a class="btn2" onclick=alertbox()>button </a>  
    <script> function alertbox() {
        alert("alert box");
    }
    </script>