Jquery没有在head中加载,而是在body标记的底部加载
Jquery not loading in head but loading on bottom of body tag
这是我的问题:正如标题所说,jQuery只有在我将脚本放在body标记的底部时才能工作。当我把它们记在脑子里时,它们就不起作用了。我使用的只是一些简单的jQuery脚本
这是我的<head>
:
<head>
<title>P site</title>
<link rel='stylesheet' href='style.css'/>
<link rel='stylesheet' type='text/css' href='jquery/css/ui-lightness/jquery-ui-1.10.4.css'/>
<link rel='stylesheet' type='text/css' href='jquery/time/jquery.ui.timepicker.css'/>
<style type="text/css">
<!--
.pagNumActive {
color: #000;
border:#060 1px solid; background-color: #D2FFD2; padding-left:3px; padding-right:3px;
}
.paginationNumbers a:link {
color: #000;
text-decoration: none;
border:#999 1px solid; background-color:#F0F0F0; padding-left:3px; padding-right:3px;
}
.paginationNumbers a:visited {
color: #000;
text-decoration: none;
border:#999 1px solid; background-color:#F0F0F0; padding-left:3px; padding-right:3px;
}
.paginationNumbers a:hover {
color: #000;
text-decoration: none;
border:#060 1px solid; background-color: #D2FFD2; padding-left:3px; padding-right:3px;
}
.paginationNumbers a:active {
color: #000;
text-decoration: none;
border:#999 1px solid; background-color:#F0F0F0; padding-left:3px; padding-right:3px;
}
-->
</style>
<?php
require 'connect.inc.php';
require 'function.php';
?>
<body>
有500多行,所以我只向您展示如何在最底部加载jQuery:
<script type='text/javascript' src='jquery/js/jquery-1.10.2.js'></script>
<script type='text/javascript' src='jquery/js/jquery-ui-1.10.4.js'></script>
<script type='text/javascript' src='jquery/time/jquery.ui.timepicker.js'></script>
<script type='text/javascript' src='jquery/js/ui.js'></script>
问题在哪里?为什么我不能将它们加载到<head>
标签中?
$(document).ready(function() {
console.log('jQuery is now ready to be executed!');
// Place jQuery code here...
});
这基本上是告诉jQuery,等待DOM加载后再对其执行操作
来源:http://api.jquery.com/ready/
我不认为你的问题是在哪里加载jquery,而是如何使用它——例如,把jquery放在头上,然后尝试这个:
$(document).ready(function(){
alert('document is fully loaded and jquery can access all elements now !');
})
如果它在代码位于以下时工作,那么主体是项目已经加载,我不知道您是否将代码放在jQuery ready函数中。
示例:
$( document ).ready(function() {
$( "p" ).text( "The DOM is now loaded and can be manipulated." );
});
来源:http://api.jquery.com/ready/
谢谢大家,我找到了解决我问题的方法,你们真的很棒。。如果有人有同样的问题,这就是我所说的,它有效。。。
正如@Jaimil Prajapati、@Damen Salvatore和@coder_ck所说,我只需要把我的jquery代码放在文档准备功能中。。这是我在脑子里想的,现在它起作用了:)
<head>
<script type='text/javascript' src='jquery/js/jquery-1.10.2.js'></script>
<script type='text/javascript' src='jquery/js/jquery-ui-1.10.4.js'></script>
<script type='text/javascript' src='jquery/time/jquery.ui.timepicker.js'></script>
<script>
$(document).ready(function() {
console.log('jQuery is now ready to be executed!');
$('#date').datepicker({ dateFormat: 'dd/mm/yy'});
$('#time').timepicker();
$(function() {
$( document ).tooltip();
});
});
</script>
</head>
如果有人遇到同样的问题,我在添加jQuery库时通过设置字符集UTF8来解决,如下所示:
<script type="text/javascript" charset="utf8" src="../jquery-3.2.1.min.js" />
相关文章:
- 页面加载时自动滚动到底部
- 滚动到底部后获取动态加载的HTML
- 每次加载页面时都加载页面底部
- 通过将$resource查询数组添加到AngularJS中另一个数组的底部来进行分页加载
- Firefox加载底部屏幕从未停止
- 如何在用户滚动到页面底部时仅加载一次数据
- 在页面加载时,底部面板应隐藏
- OnClick 会加载新的 HTML 文档,并应滚动到其底部
- jQuery在页面底部滚动时加载更多内容
- 中间的页脚加载然后粘在底部
- 使用 AJAX 调用获取动态数据,以便在用户到达底部时加载到“
- 当用户使用 Dojo 滚动到底部时加载新内容
- 如何在网站底部加载网页
- 修复了在页面底部加载时html5标签IE8不工作的问题
- 在页面底部加载脚本是否保证在执行任何脚本之前DOM都准备好了
- 滚动到底部时自动加载以前的帖子
- 页面加载时滚动到底部
- 如何设置iframe在使用jQuery加载完成后自动平滑滚动到底部
- jQuery在底部,等待<头部>直到它被加载
- 为什么在IE加载图像没有显示在页面的底部