JQuery基本语法

Original 2018-11-06 22:31:24 161
abstract:<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Document</title> <style type="text/css"> div{width:100px;height
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Document</title>
<style type="text/css">
div{width:100px;height:100px;border:1px solid #000;}

</style>
<script type="text/javascript" src="js/jquery-3.3.1.js"></script>
</head>
<body>
<div></div>
<div></div>
<div id="box2"></div>

<script type="text/javascript">
// var div1 = document.getElementsByTagName("div")[0];
// var div2 = document.getElementsByClassName("box1")[0];
// var div3 = document.getElementById('box2')
// div1.style.backgroundColor="red"
// div2.style.backgroundColor="blue"
// div3.style.backgroundColor="yellow"

$(document).ready(function(){

$(function(){
var $div1 = $("div");
var $div2 = $(".box1");
var $div3 = $("#box2");
$div1.css({
background:"red"
});
$div2.css({
background:"blue"
})
$div3.css({
background:"yellow"
})
});
});
</script>
</body>
</html>

语法和CSS很像,减少学习成本。但是我看百度腾讯都是用的jq1版,三个版本之间有什么区别吗?一般用哪个比较好呢?

Correcting teacher:灭绝师太Correction time:2018-11-07 08:56:57
Teacher's summary:你可以选用最新版,原则上是越新越好用……

Release Notes

Popular Entries