~~~
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0">
<title>珠峰培訓 - 微信:18310612838</title>
<!-- IMPORT CSS -->
<link rel="stylesheet" href="reset.min.css">
<style>
html,
body {
height: 100%;
overflow: hidden;
}
</style>
</head>
<body style="background-color: white;">
<button id="changeBtn">點擊切換BODY的顏色 白->紅->藍->綠->白</button>
<!-- IMPORT JS -->
<script>
/*
* 點擊BUTTON的時候,獲取到當前BODY的背景顏色,根據現有的背景顏色,把其更改為對應的顏色
* 1.想要操作誰,就先獲取誰
* 2.事件綁定
* 3.實現對應的需求邏輯即可
*
* body.style.backgroundColor 操作的是元素的行內樣式(只對元素行內上寫的樣式有作用),擴展思考:想要獲取元素的樣式(不論寫在哪的樣式),后面課程中會講到 getComputedStyle
*
* 在JS中獲取顏色,如果設置的時候是基于16進制或者RGB表示法寫的樣式,得到的結果一般都是RGB的染色值(我們最好把需要在JS中獲取的顏色用英文單詞表示法編寫)
* #fff 會得到rgb顏色,如果是white,那么得到的就是white
*/
let body = document.body,
changeBtn = document.getElementById('changeBtn');
changeBtn.onclick = function () {
// 每一次點擊要獲取當前最新的背景顏色
let bg = body.style.backgroundColor;
/* if (bg === 'white') {
body.style.backgroundColor = 'red';
} else if (bg === 'red') {
body.style.backgroundColor = 'blue';
} else if (bg === 'blue') {
body.style.backgroundColor = 'green';
} else {
body.style.backgroundColor = 'white';
} */
// SWITCH CASE只應用于 一個變量(JS表達式)在不同值情況下的不同操作
switch (bg) {
case 'white':
body.style.backgroundColor = 'red';
break;
case 'red':
body.style.backgroundColor = 'blue';
break;
case 'blue':
body.style.backgroundColor = 'green';
break;
default:
body.style.backgroundColor = 'white';
}
};
</script>
<script>
// 顏色是由變化規律的:紅->藍->綠->白
let body = document.body,
changeBtn = document.getElementById('changeBtn');
let arr = ['red', 'blue', 'green', 'white'],
index = -1;
changeBtn.onclick = function () {
index++;
if (index > arr.length - 1) {
// 已經到頭了,則從索引零重新開始即可
index = 0;
}
body.style.backgroundColor = arr[index];
};
/*
* arr.length-1=3 最大索引(長度-1,因為索引從零開始)
* 第一次點擊
* index++ => index=0
* body.style.backgroundColor = arr[0]; 'RED'
* 第二次點擊
* index++ => index=1
* body.style.backgroundColor = arr[1]; 'BLUE'
* 第三次點擊
* index++ => index=2
* body.style.backgroundColor = arr[2]; 'GREEN'
* 第四次點擊
* index++ => index=3
* body.style.backgroundColor = arr[3]; 'WHITE'
* 第五次點擊
* index++ => index=4
* if(4>3) => index=0
* body.style.backgroundColor = arr[0]; 'RED'
* ......
*/
</script>
</body>
</html>
~~~
~~~
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0">
<title>珠峰培訓 - 微信:18310612838</title>
<!-- IMPORT CSS -->
<link rel="stylesheet" href="reset.min.css">
<style>
</style>
</head>
<body>
<!-- <input type="text" id="inpBox">
<button id="submit">提交</button> -->
<!-- IMPORT JS -->
<script>
let inpBox = document.getElementById('inpBox'),
submit = document.getElementById('submit');
submit.onclick = function () {
// 獲取文本框中的內容(默認是字符串,需要轉換為數字)
let val = inpBox.value;
val = Number(val);
if (isNaN(val) || val < 1000 || val > 9999) {
alert('輸入的年份必須合法!');
return; //=>遇到RETURN下面代碼就不在執行了
}
if ((val % 4 === 0 && val % 100 !== 0) || val % 400 === 0) {
alert(`${val}年是閏年!`);
} else {
alert(`${val}年是平年!`);
}
}
</script>
<script>
let inpBox = document.getElementById('inpBox'),
submit = document.getElementById('submit');
submit.onclick = function () {
let val = inpBox.value;
val = Number(val);
if (isNaN(val)) {
alert('請輸入有效數字!');
return;
}
if (val % 2 === 0) {
alert(`${val}是偶數!`);
} else {
alert(`${val}是奇數!`);
}
}
</script>
<script>
let inpBox = document.getElementById('inpBox'),
submit = document.getElementById('submit');
submit.onclick = function () {
let val = inpBox.value;
val = Number(val);
if (isNaN(val)) {
alert('請輸入有效分數!');
return;
}
if (val >= 90) {
alert(`優秀!`);
} else if (val >= 80 && val < 90) {
alert(`中等`);
} else if (val >= 70 && val < 80) {
alert(`及格`);
} else {
alert(`不及格`);
}
}
</script>
工作年限:<input type="text" id="workYear">
<br>
工作薪酬:<input type="text" id="workMoney">
<br>
<button id="submit">提交</button>
<script>
let workYear = document.getElementById('workYear'),
workMoney = document.getElementById('workMoney'),
submit = document.getElementById('submit');
submit.onclick = function () {
let year = workYear.value,
money = workMoney.value;
year = Number(year);
money = Number(money);
// 最好把YEAR和MONEY做非有效數字的校驗
if (isNaN(year) || isNaN(money)) {
alert('輸入有誤,請查證');
return;
}
let result = 0; //=>設置初始值
if (year === 0) {
if (money >= 8000) {
result = money * 1.2;
} else {
result = money * 1;
}
} else if (year === 1) {
if (money >= 10000) {
result = money * 1.7;
} else {
result = money * 1.5;
}
} else {
if (money >= 12000) {
result = money * 3.2;
} else {
result = money * 3;
}
}
alert(`你應該拿到的年終獎是:¥${result.toFixed(2)}`);
}
</script>
汽油型號:<select id="modelInp">
<option value="95" selected>#95</option>
<option value="97">#97</option>
</select>
<br>
汽油升數:<input type="text" id="priceInp">
<br>
<button id="submit">提交</button>
<script>
let modelInp = document.getElementById('modelInp'),
priceInp = document.getElementById('priceInp'),
submit = document.getElementById('submit');
submit.onclick = function () {
let model = modelInp.value,
price = priceInp.value;
model = Number(model);
price = Number(price);
if (isNaN(model) || isNaN(price)) {
alert('輸入有誤,請查證');
return;
}
let result = model === 95 ? (price >= 20 ? price * 5.9 : price * 6) : (price >= 30 ? price * 6.95 : price *
7);
if (model === 95) {
if (price >= 20) {
result = price * 5.9;
} else {
result = price * 6;
}
} else {
if (price >= 30) {
result = price * 6.95;
} else {
result = price * 7;
}
}
alert(`支付總價:¥${result.toFixed(2)}`);
}
</script>
</body>
</html>
~~~
- 0001.開課說明
- 0002.ECMAScript的發展歷程
- 0003.WEB2.0時代-服務器端渲染,前后端不分離
- 0004.WEB2.0時代-前后端分離模式
- 0005.大前端時代概述
- 0006.前端需要的技術棧和學習技巧
- 0007.瀏覽器
- 0008.JS的三部分組成
- 0009.JS中創建變量的6種形式
- 0010.JS中變量的命名規范
- 0011.JS中的數據類型分類
- 0012.JS中常用的幾種輸出方式
- 0013.number屬性類型詳細解讀1
- 0014.number數據類型詳細解讀2
- 0015.string數據類型詳細解讀1
- 0016.string數據類型詳細解讀2
- 0017.boolean數據類型詳細解讀
- 0018.object數據類型詳細解讀1
- 0019.object數據類型詳細解讀2
- 0020.談談學習
- 0021.數據類型檢測
- 0022.瀏覽器底層渲染機制(堆棧內存和數據類型區別)
- 0023.關于數據類型區別的面試題
- 0024.課后作業講解:數據類型轉換
- 0025.課后作業講解:堆棧內存處理
- 0026.課后作業講解:阿里的一道經典面試題
- 0027.JS中三種常用的判斷語句
- 0028.小實戰:開關燈特效
- 0029.FOR循環和FOR IN循環
- 0030.課后作業講解:關于循環判斷和數據轉化
- 0031.課后作業講解:關于DOM對象的深入理解
- 0032.關于元素集合的相關操作(奇偶行變色)
- 0033.課后作業講解:邏輯思維判斷題
- reset.min.css
- 0034.(復習)前四天內容的綜合復習梳理
- 0035.初窺函數:函數的作用、語法、形參
- 0036-0038.選項卡案例
- 0039.隔行變色案例:進一步強化自定義屬性編程思想
- 0040.其它作業題的講解(自定義屬性強化)
- 0041.函數創建和執行的堆棧運行機制
- 0042.函數中的形參和實參
- 0043.函數中的實參集合ARGUMENTS
- 0044.函數中的返回值RETURN
- 0045.箭頭函數和匿名函數
- 0046.兩個等于比較時候的數據類型轉換規則
- 0047.數組的基礎結構和常規操作
- 0048.數組常用方法:增刪改的五個方法
- 0049.數組常用方法:查詢、拼接、轉換為字符串
- 0050.數組常用方法:檢測是否包含、排序和迭代
- 0051.數組去重:雙FOR循環(數組塌陷和SPLICE刪除優化)
- 0052.數組去重:對象鍵值對方式(ES6中SET)
- 0053.Math數學函數對象中常用的方法
- 0054.String字符串中常用的方法
- 0055.實戰案例:時間字符串格式化
- 0056.實戰案例:queryURLParams1
- 0057.實戰案例:queryURLParams2
- 0058.實戰案例:獲取四位不重復的驗證碼
- 0059.階段作業題講解1(基礎知識)
- 0060.階段作業題講解2(實戰案例)
- 0061-0062.DOM操作中相關知識的復習
- 0063.DOM中的節點操作1
- 0064.DOM中的節點操作2
- utils
- 65.關于DOM的增刪改