亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

jquery 的基本語法架構

原創(chuàng) 2019-05-27 19:30:09 278
摘要:<!DOCTYPE html><html lang="en"><head>    <meta charset="UTF-8">    <title>jQuery導入與代碼架構</title></head><body> &nb

<!DOCTYPE html>
<html lang="en">
<head>
   <meta charset="UTF-8">
   <title>jQuery導入與代碼架構</title>
</head>
<body>
   <script src="static/js/jquery-3.4.1.js"></script>
   <script>
// jQuery 和 $
console.log( $ ); // 返回一個函數
console.log( jQuery ); // 返回一個函數
console.log( $ === jQuery); // true

       // jQuery中的方法分為二類
// 1. 靜態(tài)方法, 直接通過 $ 調用,例如: $.ajax(), $.trim()
console.log('   admin   '.length); // 11
console.log($.trim('  admin    ').length); // 5

       // 2. 實例方法, 定義在jQuery.prototype, 即定義在它的原型對象,需要通過它的實例調用
console.log($.prototype); // 查看定義在$原型對象上的,被所有實例所共享的方法
$('body').append($('<h2>Hello jQuery</h2>')).css('color', 'red');
// append(), css()就是定義在$.prototype上的方法, 需要通過jQuery對象的實例來方法

// 代碼的基本架構: html文檔準備就緒之后,就立即執(zhí)行ready中的回調函數中的代碼
$(document).ready(function (){
// ...
});
// 還可以進一步簡化, 功能是一樣的, 以后咱們就使用這種語法了
$(function () {
//...
})
</script>
</body>
</html>

批改老師:天蓬老師批改時間:2019-05-28 16:55:45
老師總結:如果你的jquery在在js代碼代碼之前加載的, 也可以不使用這種結構. <script src="jqueyr.js"></script> <script> 可以直接寫jQ代碼了, 不必$(function () {}} </script>

發(fā)佈手記

熱門詞條