简体   繁体   中英

jQuery to Javascript code converting

I have not a good Javascript knowledge, but I'm kinda good with jQuery though. I want to change some jQuery code to pure Javascript, but I have no idea how to do it.

$(document).ready(function() 
{
    $('#block').one('click', function()
    {
       $(this).val('{L_SEND_CONFIRM}').removeClass('button1');
       $('#replacement').val('{L_BLOCK_CODE}');
    });
});

Anyone willing to help me out please?

PS: Sorry for asking such a dumb question, I really need to learn Javascript myself ASAP.

This is a rough equivalent (there are subtleties that if you want to address start getting annoying, thus the need for frameworks in the first place):

window.onload = function() {
    document.getElementById('block').onclick = function() {
        this.onclick = '';
        this.value = '{L_SEND_CONFIRM}';
        this.className = this.className.replace('button1','');
        document.getElementById('replacement').value = '{L_BLOCK_CODE}';
    }
}

onready and onload are two different beasts.

onready fires when the DOM is ready, but graphics may not have been loaded yet.

onload fires when everything needed, including graphics, have finished.

I like this library here to handle the onready stuff. It uses DOM methods for browsers that support it and uses a weird IE hack when it must:

https://github.com/ded/domready

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM