$()使用
1.在head中
在head中必须写在$(function () { })内
2.在body中
不用写$(function () { }),写了反而会导致有些自定义的函数无法调用
命名规则
最好用$+变量名,不然有时会在chrome中会报错,具体原因暂时还不知道,比如:let $a=$("a");
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<script src="https://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.7.2.min.js"> </script>
<style>
a{
color:#008c8c;
}
</style>
</head>
<body>
<a href="https://www.baidu.com">百度</a>
<script>
let $a=$("a");
$a.hover(function(){
$a.css({
"color":"red"
});
},function(){
$a.css({
"color":"#008c8c"
});
})
</script>
</body>
</html>