Javascript window.onload not firing
Javascript window.onload not firing
我正在尝试编写一个JavaScript函数,该函数强制元素具有样式显示=块。目前,它被设置为显示=无被另一个javascript。
我认为window.onload
可以解决问题,因为代码不会被以前的JS覆盖。下面的代码曾经工作过,现在函数甚至没有触发。
谁能帮忙?
window.onload = function () // It sets the class of the unordered list when the page has been loaded.
{
ul.style.display = "block!important"; // Display all the child items
}
您需要
在事件侦听器的回调中获取ul
,因为如果您之前这样做,DOM 不会完全加载。
document.addEventListener("DOMContentLoaded", function(event) {
var ul = document.getElementById("my-ul");
ul.style.display = "block!important";
});
如果你想要一个更跨浏览器的解决方案,你可以用JQuery来做到这一点:
$(document).ready(function() {
$('#my-ul').css('display', 'block!important');
});
你可以在 css 中做到这一点:
#my-ul {
display: block!important;
}
您的ul
应采用以下解决方案的工作方式:
<ul id="my-ul">
你不能
使用这样的ul.style.display
。
使用document. getElementsByTagName('ul').style.display = "block !important"
window.onload = function() ... 正在定义一个函数。只需在使用 window.onload() 关闭它后立即调用该函数; 几个小时后为我工作
相关文章:
- WebSocket onmessage not firing
- Backbone model.change() not firing
- codemirror onKeyEvent not firing
- Dojo onBeforeTransitionIn not firing
- CSS TransitionEnd not firing
- RegisterClientScriptBlock - not firing
- GWT History.back() is not firing onValueChangeHandler
- Signalr connection.start.done not firing
- Javascript XMLHttpRequest onreadystatechanged not firing?
- jstree select_node.jstree not firing
- Jquery not firing
- jQuery.on("drop") not firing
- Javascript window.onload not firing
- MVC 5 javascript not firing
- Javascript FileReader onload not firing
- setTimeout not firing jQuery
- setInterval() not firing
- $.getJSON not firing console.log
- Sails.js IO.socket not firing
- react componentDidMount not firing