批改状态:未批改
老师批语:
代码如图
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>有关JQuery的添加方式</title>
<style type="text/css">
ul{
margin: 20px;
padding: 10px;
overflow: hidden;
list-style-type: none;
}
li{
width: 30px;
height: 30px;
margin-right: 10px;
background-color: skyblue;
float: left;
border-radius: 50%;
text-align: center;
font-weight: border;
font-size: 1.2em;
box-shadow: 2px 2px 2px #989898;
}
</style>
<script type="text/javascript" src="http://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"> </script>
<script type="text/javascript">
// $('h2').css('color','blue')
// h2为运行已经运行jquery代码
$(document).ready(function(){
$('h2').css('color','blue')
});
// 防止文档在完全加载(就绪)之前运行 jQuery 代码
// 简写方式:
// $(function(){
// $('h2').css('color','blue')
// });
</script>
</head>
<body>
<h2>有关JQuery</h2>
<ul>
<li>1</li>
<li>2</li>
<li>3</li>
<li>4</li>
<li>5</li>
<li>6</li>
<li>7</li>
<li>8</li>
<li>9</li>
<li>10</li>
</ul>
<!-- 有关添加JQuery的方法 -->
<!-- 第一种添加方式从Jquery.com中下载Jquery库,然后引用本地文件
<script type="text/javascript" src="../jqery/jqery-3.3.1.js"></script> -->
<!-- 第二种是网络在线从CDN中直接引用JQuery库
<script type="text/javascript" src="https://cdn.bootcss.com/jquery/3.3.1/core.js"></script> -->
</body>
</html>知识总结:
认识到了jQuery是JavaScript的一种形式
jquery是为了用更少的代码做更多的东西
为了防止jQuery在内容未运行前提前运行导致失效,应把jQuery代码放入$(document).ready(function(){
jQuery代码});
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号