博客列表 >初识JQuery

初识JQuery

其琛的博客
其琛的博客原创
2018年04月03日 18:15:39520浏览

代码如图

<!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>

知识总结:

  1. 认识到了jQuery是JavaScript的一种形式

  2. jquery是为了用更少的代码做更多的东西

  3. 为了防止jQuery在内容未运行前提前运行导致失效,应把jQuery代码放入$(document).ready(function(){

    jQuery代码});

声明:本文内容转载自脚本之家,由网友自发贡献,版权归原作者所有,如您发现涉嫌抄袭侵权,请联系admin@php.cn 核实处理。
全部评论
文明上网理性发言,请遵守新闻评论服务协议