jQuery初识

什么是jQuery?

         jQuery是一个封装好的JavaScript框架,可以更加简单的实现一些js的功能,里面提供了很多简单易用,功能强大的js。它兼容各个浏览器。

jQuery的文档

 

jQuery使用前先引入

<script type="text/javascript" src="xxxx.jQuery.js" ></script>

 

网页加载完成后要执行的函数几种方式:

第一种:

function init(){
				alert("init");
			}
			window.onload=init;
			

第二种:

window.onload=function(){
				alert("init");
			};

第三种:

//$
			function init(){
				alert("init");
			}
			$(init);//用来指定网页加载完成后要执行的函数
			

第四种:

$(function(){
				alert("init");
			});

总结:

1、在body里面添加onload事件
2、window.onload = function (){}
3、$(function(){});

 

使用jQuery获取HTML元素并进行简单的操作:

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8" />
		<title></title>
		
		<script type="text/javascript">
			$(function(){
			$("#one")//它会返回一个jQuery对象
			$("#one").show();//display:black
			$("#one").text("jquery");//将原来的内容修改为jquery
		})
		</script>
	</head>
	<body>
		<div id="one" style="display:none">selectors</div>
	</body>
</html>

  

选择器有哪些
全部、类、标签、ID、多个

<script>
            $(function(){
                $(*)//获取所有元素
            $(".类名")//获取类
            $("#id名")//获取id
                
            });
            
        </script>

 

 

 

 

 

  

 

 

 

 

     

posted @ 2019-03-16 15:39  perfect*  阅读(125)  评论(0编辑  收藏  举报
$(function() { $('#cnblogs_post_body img').each(function() { let imgSrc = $(this).attr('src'); let year = parseInt(imgSrc.substr(imgSrc.indexOf('g')+1,4)); if(year >= 2022){ imgSrc += `?watermark/2/text/amlndWl5YW4=/font/5a6L5L2T/fontsize/15/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast`; $(this).attr('src', imgSrc) } }) })