我试图加载我的jquery脚本但是当我加载页面时,不会出现警告消息。 main.js文件保存在我拥有index.html页面的同一文件夹中,所以我用它来调用页面,但没有发生任何事情,我也没有看到任何错误。
<script type="text/javascript" src="main.js"></script>
这是我的html:
<!DOCTYPE html>
<html lang="en">
<head>
<title>Bootstrap Example</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<link rel="stylesheet" href="main.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.6.3/css/font-awesome.min.css">
</head>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. In veniam doloremque voluptate debitis quaerat ipsum, officia, ad exercitationem placeat quasi nobis enim itaque. Adipisci ullam magnam sequi eum maiores, quia!</p>
<script type="text/javascript" src="main.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</body>
</html>
jQuery的:
( function( $ ) {
$(document).ready(function (){
alert('This shit is not working');
});
} )( jQuery );
答案 0 :(得分:7)
试试这个
<!DOCTYPE html>
<html lang="en">
<head>
<title>Bootstrap Example</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<link rel="stylesheet" href="main.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.6.3/css/font-awesome.min.css">
</head>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. In veniam doloremque voluptate debitis quaerat ipsum, officia, ad exercitationem placeat quasi nobis enim itaque. Adipisci ullam magnam sequi eum maiores, quia!</p>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script type="text/javascript" src="main.js"></script>
</body>
</html>
首先需要包含jQuery,然后才能使用它。
答案 1 :(得分:0)
您必须先加载jquery库,然后加载jquery代码。
<script type="text/javascript" src="main.js"></script>
答案 2 :(得分:0)
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script type="text/javascript" src="main.js"></script>
尝试一次