說明:本文使用的部分插圖來自Jon Duckett先生的*HTML and CSS: Design and Build Websites*一書,這是一本很是棒的前端入門書,有興趣的讀者能夠在亞馬遜或者其餘網站上找到該書的購買連接。javascript
文本的大小和字型(font-size / font-family)
粗細、樣式、拉伸和裝飾(font-weight / font-style / font-stretch / text-decoration)
行間距(line-height)、字母間距(letter-spacing)和單詞間距(word-spacing)
對齊(text-align)方式和縮進(text-ident)
連接樣式(:link / :visited / :active / :hover)
CSS3新屬性
盒子大小的控制(width / height)
盒子的邊框、外邊距和內邊距(border / margin / padding)
盒子的顯示和隱藏(display / visibility)
CSS3新屬性
控制元素的位置(position / z-index)
網站佈局
適配屏幕尺寸
if...else...
switch...cas...default...
for
循環while
循環do...while
循環this
關鍵字delete
關鍵字Number
/ String
/ Boolean
/ Symbol
/ Array
/ Function
Date
/ Error
/ Math
/ RegEx
/ Object
/ Map
/ Set
JSON
/ Promise
/ Generator
/ Reflect
/ Proxy
window
對象的屬性和方法history
對象
forward()
/ back()
/ go()
location
對象navigator
對象screen
對象getElementById()
/ querySelector()
getElementsByClassName()
/ getElementsByTagName()
/ querySelectorAll()
parentNode
/ previousSibling
/ nextSibling
/ children
/ firstChild
/ lastChild
nodeValue
innerHTML
/ textContent
/ createElement()
/ createTextNode()
/ appendChild()
/ insertBefore()
/ removeChild()
className
/ id
/ hasAttribute()
/ getAttribute()
/ setAttribute()
/ removeAttribute()
load
/ unload
/ error
/ resize
/ scroll
keydown
/ keyup
/ keypress
click
/ dbclick
/ mousedown
/ mouseup
/ mousemove
/ mouseover
/ mouseout
focus
/ blur
input
/ change
/ submit
/ reset
/ cut
/ copy
/ paste
/ select
target
(有些瀏覽器使用srcElement)type
cancelable
preventDefault()
stopPropagation()
(低版本IE中的cancelBubble)screenX
和screenY
pageX
和pageY
clientX
和clientY
keyCode
屬性(有些瀏覽器使用which
)String.fromCharCode(event.keyCode)
DOMContentLoaded
hashchange
beforeunload
客戶端存儲 - localStorage
和sessionStorage
localStorage.colorSetting = '#a4509b'; localStorage['colorSetting'] = '#a4509b'; localStorage.setItem('colorSetting', '#a4509b');
獲取位置信息 - geolocation
navigator.geolocation.getCurrentPosition(function(pos) { console.log(pos.coords.latitude) console.log(pos.coords.longitude) })
從服務器獲取數據 - Fetch API
繪製圖形 - <canvas>
的API
音視頻 - <audio>
和<video>
的API
<script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.min.js"></script> <script> window.jQuery || document.write('<script src="js/jquery-3.3.1.min.js"></script>') </script>
html()
/ text()
/ replaceWith()
/ remove()
before()
/ after()
/ prepend()
/ append()
/ remove()
/ clone()
/ unwrap()
/ detach()
/ empty()
/ add()
attr()
/ removeAttr()
/ addClass()
/ removeClass()
/ css()
val()
find()
/ parent()
/ children()
/ siblings()
/ next()
/ nextAll()
/ prev()
/ prevAll()
filter()
/ not()
/ has()
/ is()
/ contains()
eq()
height()
/ width()
/ innerHeight()
/ innerWidth()
/ outerWidth()
/ outerHeight()
offset()
/ position()
/ scrollLeft()
/ scrollTop()
show()
/ hide()
/ toggle()
fadeIn()
/ fadeOut()
/ fadeTo()
/ fadeToggle()
slideDown()
/ slideUp()
/ slideToggle()
delay()
/ stop()
/ animate()
ready()
/ load()
on()
/ off()
<script> $(document).ready(function() { }); </script>
<script> $(function() { }); </script>
先引入其餘庫再引入jQuery的狀況。
<script src="other.js"></script> <script src="jquery.js"></script> <script> jQuery.noConflict(); jQuery(function() { jQuery('div').hide(); }); </script>
先引入jQuery再引入其餘庫的狀況。
<script src="jquery.js"></script> <script src="other.js"></script> <script> jQuery(function() { jQuery('div').hide(); }); </script>
Ajax是一種在無需從新加載整個網頁的狀況下,可以更新部分網頁的技術。
先後端分離開發(前端渲染)必選框架。
引入Vue的JavaScript文件,咱們仍然推薦從CDN服務器加載它。
<script src="https://cdn.jsdelivr.net/npm/vue"></script>
數據綁定(聲明式渲染 )。
<div id="app"> <h1>{{ product }}庫存信息</h1> </div> <script src="https://cdn.jsdelivr.net/npm/vue"></script> <script> const app = new Vue({ el: '#app', data: { product: 'iPhone X' } }); </script>
條件與循環。
<div id="app"> <h1>庫存信息</h1> <hr> <ul> <li v-for="product in products"> {{ product.name }} - {{ product.quantity }} <span v-if="product.quantity === 0"> 已經售罄 </span> </li> </ul> </div> <script src="https://cdn.jsdelivr.net/npm/vue"></script> <script> const app = new Vue({ el: '#app', data: { products: [ {"id": 1, "name": "iPhone X", "quantity": 20}, {"id": 2, "name": "華爲 Mate20", "quantity": 0}, {"id": 3, "name": "小米 Mix3", "quantity": 50} ] } }); </script>
計算屬性。
<div id="app"> <h1>庫存信息</h1> <hr> <ul> <li v-for="product in products"> {{ product.name }} - {{ product.quantity }} <span v-if="product.quantity === 0"> 已經售罄 </span> </li> </ul> <h2>庫存總量:{{ totalQuantity }}臺</h2> </div> <script src="https://cdn.jsdelivr.net/npm/vue"></script> <script> const app = new Vue({ el: '#app', data: { products: [ {"id": 1, "name": "iPhone X", "quantity": 20}, {"id": 2, "name": "華爲 Mate20", "quantity": 0}, {"id": 3, "name": "小米 Mix3", "quantity": 50} ] }, computed: { totalQuantity() { return this.products.reduce((sum, product) => { return sum + product.quantity }, 0); } } }); </script>
處理事件。
<div id="app"> <h1>庫存信息</h1> <hr> <ul> <li v-for="product in products"> {{ product.name }} - {{ product.quantity }} <span v-if="product.quantity === 0"> 已經售罄 </span> <button @click="product.quantity += 1"> 增長庫存 </button> </li> </ul> <h2>庫存總量:{{ totalQuantity }}臺</h2> </div> <script src="https://cdn.jsdelivr.net/npm/vue"></script> <script> const app = new Vue({ el: '#app', data: { products: [ {"id": 1, "name": "iPhone X", "quantity": 20}, {"id": 2, "name": "華爲 Mate20", "quantity": 0}, {"id": 3, "name": "小米 Mix3", "quantity": 50} ] }, computed: { totalQuantity() { return this.products.reduce((sum, product) => { return sum + product.quantity }, 0); } } }); </script>
用戶輸入。
<div id="app"> <h1>庫存信息</h1> <hr> <ul> <li v-for="product in products"> {{ product.name }} - <input type="number" v-model.number="product.quantity" min="0"> <span v-if="product.quantity === 0"> 已經售罄 </span> <button @click="product.quantity += 1"> 增長庫存 </button> </li> </ul> <h2>庫存總量:{{ totalQuantity }}臺</h2> </div> <script src="https://cdn.jsdelivr.net/npm/vue"></script> <script> const app = new Vue({ el: '#app', data: { products: [ {"id": 1, "name": "iPhone X", "quantity": 20}, {"id": 2, "name": "華爲 Mate20", "quantity": 0}, {"id": 3, "name": "小米 Mix3", "quantity": 50} ] }, computed: { totalQuantity() { return this.products.reduce((sum, product) => { return sum + product.quantity }, 0); } } }); </script>
經過網絡加載JSON數據。
<div id="app"> <h2>庫存信息</h2> <ul> <li v-for="product in products"> {{ product.name }} - {{ product.quantity }} <span v-if="product.quantity === 0"> 已經售罄 </span> </li> </ul> </div> <script src="https://cdn.jsdelivr.net/npm/vue"></script> <script> const app = new Vue({ el: '#app', data: { products: [] }, created() { fetch('https://jackfrued.top/api/products') .then(response => response.json()) .then(json => { this.products = json }); } }); </script>
Vue爲商業項目開發提供了很是便捷的腳手架工具vue-cli,經過工具能夠省去手工配置開發環境、測試環境和運行環境的步驟,讓開發者只須要關注要解決的問題。
基於Vue 2.0的桌面端組件庫,用於構造用戶界面,支持響應式佈局。
引入Element的CSS和JavaScript文件。
<!-- 引入樣式 --> <link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css"> <!-- 引入組件庫 --> <script src="https://unpkg.com/element-ui/lib/index.js"></script>
一個簡單的例子。
<!DOCTYPE html>
<html>
<head> <meta charset="UTF-8"> <link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css"> </head> <body> <div id="app"> <el-button @click="visible = true">點我</el-button> <el-dialog :visible.sync="visible" title="Hello world"> <p>開始使用Element吧</p> </el-dialog> </div> </body> <script src="https://unpkg.com/vue/dist/vue.js"></script> <script src="https://unpkg.com/element-ui/lib/index.js"></script> <script> new Vue({ el: '#app', data: { visible: false, } }) </script> </html>
使用組件。
<!DOCTYPE html>
<html>
<head> <meta charset="UTF-8"> <link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css"> </head> <body> <div id="app"> <el-table :data="tableData" stripe style="width: 100%"> <el-table-column prop="date" label="日期" width="180"> </el-table-column> <el-table-column prop="name" label="姓名" width="180"> </el-table-column> <el-table-column prop="address" label="地址"> </el-table-column> </el-table> </div> </body> <script src="https://unpkg.com/vue/dist/vue.js"></script> <script src="https://unpkg.com/element-ui/lib/index.js"></script> <script> new Vue({ el: '#app', data: { tableData: [ { date: '2016-05-02', name: '王一霸', address: '上海市普陀區金沙江路 1518 弄' }, { date: '2016-05-04', name: '劉二狗', address: '上海市普陀區金沙江路 1517 弄' }, { date: '2016-05-01', name: '楊三萌', address: '上海市普陀區金沙江路 1519 弄' }, { date: '2016-05-03', name: '陳四吹', address: '上海市普陀區金沙江路 1516 弄' } ] } }) </script> </html>
百度出品的開源可視化庫,經常使用於生成各類類型的報表。
Bulma是一個基於Flexbox的現代化的CSS框架,其初衷就是移動優先(Mobile First),模塊化設計,能夠輕鬆用來實現各類簡單或者複雜的內容佈局,即便不懂CSS的開發者也可以使用它定製出漂亮的頁面。
<!DOCTYPE html>
<html lang="en"> <head> <meta charset="UTF-8"> <title>Bulma</title> <link href="https://cdn.bootcss.com/bulma/0.7.4/css/bulma.min.css" rel="stylesheet"> <style type="text/css"> div { margin-top: 10px; } .column { color: #fff; background-color: #063; margin: 10px 10px; text-align: center; } </style> </head> <body> <div class="columns"> <div class="column">1</div> <div class="column">2</div> <div class="column">3</div> <div class="column">4</div> </div> <div> <a class="button is-primary">Primary</a> <a class="button is-link">Link</a> <a class="button is-info">Info</a> <a class="button is-success">Success</a> <a class="button is-warning">Warning</a> <a class="button is-danger">Danger</a> </div> <div> <progress class="progress is-danger is-medium" max="100">60%</progress> </div> <div> <table class="table is-hoverable"> <tr> <th>One</th> <th>Two</th> </tr> <tr> <td>Three</td> <td>Four</td> </tr> <tr> <td>Five</td> <td>Six</td> </tr> <tr> <td>Seven</td> <td>Eight</td> </tr> <tr> <td>Nine</td> <td>Ten</td> </tr> <tr> <td>Eleven</td> <td>Twelve</td> </tr> </table> </div> </body> </html>
用於快速開發Web應用程序的前端框架,支持響應式佈局。