jQuery库的引入
<script
src="https://code.jquery.com/jquery-1.12.4.js"
integrity="sha256-Qw82+bXyGq6MydymqBxNPYTaUXXq7c8v3CwiYwLLNXU="
crossorigin="anonymous">
</script>
例子1
//原生js的固定写法
window.onload = function (ev) {
var img = document.getElementsByTagName("img")[0]
console.log(img);
var width = window.getComputedStyle(img).width;
console.log("onload",width);
}
//2.jQuery的固定写法
$(document).ready(function () {
var $img = $("img")[0];
console.log($img);
var $width = $img.width();
console.log("ready",$width);
});
效果
区别1
js会在执行完Dom 并且等图片也加载完之后才会执行,
jquery在执行完Dom之后就会直接执行去宽度,不会去等图片加载
例2
window.onload = function (ev) {
alert("hellow js1");
}
window.onload = function (ev) {
alert("hellow js2");
}
js在运行时,会先弹出hellow js1 再弹出hellow js2 二者顺序执行。
<constructor-arg>
<bean class="java.text.SimpleDateFormat">
<constructor-arg value="yyyy-MM-dd" />
</bean>
</constructor-arg>
<constructor-arg value="true" />
区别2
原生js,如果编写了多个入口函数,后面的就会覆盖前面的。
jQuery编写多个入口函数,会依次执行,后面的不会覆盖前面的。