我正在尝试向我的网站添加一个简单的预加载程序,并在控制台Uncaught TypeError: a.indexOf is not a function中得到这个错误
HTML index.html
<html class="js">
<head>
<script type="text/javascript" src="assets/js/jquery.min.js"></script>
<link rel="stylesheet" href="assets/css/style.css">
</head>
<body>
<script type="text/javascript">
jQuery(document).ready(function($) {
$(window).load(function(){
$('#preloader').fadeOut('slow',function(){$(this).remove();});
});
});
</script>
<div id="preloader"></div>
</body>
</html>CSS style.css
.js div#preloader {
position: fixed;
left: 0;
top: 0;
z-index: 999;
width: 100%;
height: 100%;
overflow: visible;
background: #143441 url('assets/img/loader.gif') no-repeat center center;
}这只显示了在加载结束后不断旋转的gif。
发布于 2019-03-26 17:57:59
我搜索了一下,找到了一个解决方案。问题是在.load事件别名中,需要替换.on。
示例:
$(window).load(function(){...});
变成:
$(window).on('load', function(){ ...});
https://stackoverflow.com/questions/55363084
复制相似问题