如何在HTML加载完成之前调用JS函数? [英] How to call JS function before HTML load completed?

查看:310
本文介绍了如何在HTML加载完成之前调用JS函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了一个JS函数来隐藏HTML中的一些元素,并使用 window.onload()来调用这个函数。但是在HTML加载完成之后,存在一个问题,即 window.onload()调用函数,这使得这些元素首先显示在网页中,并等待几秒钟后消失。那么我是否有一些方法可以让它在开始时隐藏在网页的加载过程中?

I write a JS function to hide some elements in HTML and use window.onload() to call this function. But there is a problem that window.onload() call functions after HTML load completed, which makes those elements display in the webpage first and wait a few seconds they disappeared. So do I have some methods to make it be hidden at the beginning in loading process of this webpage?

这是我的JS代码:

function toggle_visibility(id) {
    var e = document.getElementById(id);
    e.style.display = 'none';
}

window.onload = function () {
    toggle_visibility("excelDataTable_epgd");
    toggle_visibility("EPGD_SIZE");
}


推荐答案

首先没有可见性,然后启用页面加载后显示的那些?

How about you make the default visibility none first and then enable the ones you want to display after page load?

这篇关于如何在HTML加载完成之前调用JS函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆