To bind the click event of the login button to a function named login(), you can add the following JavaScript code inside the <script> tags in the <head> section of the HTML code:

<script>
    function login() {
        // Code to handle the login functionality
    }

    document.addEventListener('DOMContentLoaded', function() {
        var btn = document.querySelector('.btn');
        btn.addEventListener('click', login);
    });
</script>

In the above code, the login() function is defined to handle the login functionality. The document.addEventListener('DOMContentLoaded', function() { ... }) code is used to ensure that the JavaScript code is executed only after the HTML document has been completely loaded.

Inside the anonymous function, the btn variable is assigned the reference to the login button using the document.querySelector('.btn') method. Then, the addEventListener() method is used to bind the click event to the login function

!DOCTYPE htmlhtml lang=enhead meta charset=UTF-8 meta name=viewport content=width=device-width initial-scale=10 titleDocumenttitle style margin 0; padding 0;

原文地址: https://www.cveoy.top/t/topic/hO39 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录