Internal Link (jump to link)

This question already has an answer here:

  • How to create an HTML button that acts like a link? 27 answers

  • You can link to any element you like. Just give the element an id and set the URL to #that_id .

    If you want to link from something, use a real link. It is what links are designed for. They do it really easily (and natively, and in a screen reader and search engine friendly fashion). If you want to link from something that looks like a button, then use a link and apply CSS to make it look like a button.

    If you really, really want to use a button (hint: don't). Then you can bind JavaScript to it:

    document.querySelector('#my_button').addEventListener('click', function (event) {
        location = "#my_id";
    });
    

    Yes it is possible. Internal links don't have to point to an anchor tag.


    you could use JavaScript to do something like that onclick="document.location+='#goToAnchor';return false;"

    Doesn't seem like the best practice though.

    链接地址: http://www.djcxy.com/p/36570.html

    上一篇: 如何链接Web应用程序中的两个HTML页面?

    下一篇: 内部链接(跳转到链接)