[removed]void(0) or onclick=“return false” for - which is better?

前端 未结 2 1741
死守一世寂寞
死守一世寂寞 2021-01-04 07:47

There is a javascript-based interface - so I need not to support work without javascript.

I have an

Something

e

相关标签:
2条回答
  • 2021-01-04 08:16

    Neither. If your link doesn't go anywhere, don't use an <a> element. Use a <span> or something else appropriate and add CSS to style it as you wish.

    0 讨论(0)
  • 2021-01-04 08:35

    Both are poor choices. Presentation shouldn't mix with content. That means no javascript: URIs, and definitely no onclick attributes.

    The way to do it:

    <a id="myLink">Something</a>
    <script>
        function myFunction(...) { ... }
        document.getElementById('myLink').addEventListener('click', myFunction, false);
    </script>
    0 讨论(0)
提交回复
热议问题