<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ??一站式輕松地調用各大LLM模型接口,支持GPT4、智譜、豆包、星火、月之暗面及文生圖、文生視頻 廣告
                [TOC] # 案例1:獲取頁面中的五個按鈕 ![](https://img.kancloud.cn/6e/fa/6efa87d0615fa6b1066104c67f8ff96b_432x134.png) ## 知識點:節點對象Element ``` Live Node = document.getElementById("id") Live Node List = document.getElementsByClassName("class") Live Node List = document.getElementsByName("name") Live Node List = document.getElementsByTagName("tagname") Static Node = document.querySelector("selector") Static Node List = document.querySelectorAll("selector") ``` # 案例2:實現網頁計算器 ![](https://img.kancloud.cn/f8/42/f842fff11eeab6766be97c4a41dca3c9_297x187.gif) ## 知識點1:獲取/修改值和文本 ![](https://img.kancloud.cn/7e/43/7e437b850b8aa2a3ad1b1e792166d8de_339x145.png) > ele.innerHTML或ele.innerText = newText > ele.value = newValue ## 知識點2:函數調用及傳參 * 通過事件調用 * 通過鏈接調用 > 函數形參不需要var > 函數返回值需要return ## 知識點3:全局函數eval | 方法名 | 描述 | | --- | --- | | **isNaN(X)** | 判斷X是否為非數字 | | **eval(X)** | 計算X字符串(作為腳本代碼執行) | * [ ] 試一試 ![](https://img.kancloud.cn/f9/65/f965539a5a987815182d8259a61b37ab_311x107.png) # 案例3:實現網頁開關燈 ![](https://img.kancloud.cn/58/77/58775cc3b6fc23dee16bbccb1591859f_239x312.gif) > `ele.style.XXX = newValue` > `ele.attr = newValue` ![](https://img.kancloud.cn/0d/35/0d35ffe65bfb298cdc717abf0b3d6f7c_782x216.png) # 案例4:留言板 ![](https://img.kancloud.cn/f4/64/f464b76aeb7d295da63c29686ccc29ef_445x314.png) ## 知識點1:Array初始化 ![](https://img.kancloud.cn/33/45/33457ebf39753d2e19f7aafbd0a7a08c_267x343.png) ## 知識點:Array常用方法 ![](https://img.kancloud.cn/40/0e/400efb42142167625c46482b696dbd29_329x274.png) # 案例5:將URL中的參數提取為對象 ![](https://img.kancloud.cn/8e/1c/8e1c5afc2ba8b3d6827bceea5a9609e7_556x238.png) ## 知識點1:String初始化及常用方法 ![](https://img.kancloud.cn/48/4f/484fd598cd2b1c1d8adcbe52cba93978_390x277.png) 1. 字符長度 `str.length` 2. 字符方法 ``` charAt(index) //獲取指定位置處字符 charCodeAt(index) //獲取指定位置處字符的ASCII碼 str[0] //HTML5,IE8+支持 和charAt(0)等效 ``` 3. 位置方法 ``` indexOf(char) //返回指定內容在元字符串中的位置 lastIndexOf() //從后往前找,只找第一個匹配的 ``` 4. 字符串操作方法 ``` concat() //拼接字符串,等效于+,+更常用 slice() //從start位置開始,截取到end(取不到) substring() //從start位置開始,截取到end(取不到) substr() //從start位置開始,截取length個字符 ``` 5. 其他 ``` trim() //只能去除字符串前后的空白 to(Locale)UpperCase() //轉換大寫 to(Locale)LowerCase() //轉換小寫 search() replace() split() 按照特定字符將字符串分割為數組 ``` ## 知識點2:對象的創建和訪問 ``` var x = {}; var car = {type:"Fiat", model:500, online:false}; var obj= { name1: "value1", name2 : function() { return this.name1 + " " + this.name2; } }; ``` ## 知識點3:創建對象并訪問 * [ ] 訪問對象屬性 ``` obj.name1; obj["name2"]; ``` * [ ] 訪問對象方法并執行 ```res = obj.funName();``` * [ ] 試一試 ![](https://img.kancloud.cn/6b/39/6b3912d87b8068b680ac597bebbeb91d_699x378.png) > 讀取了對象不存在的屬性,屬性值為undefined ## 知識點4:URL編碼解碼 | 方法名 | 描述 | | --- | --- | | **encodeURI(X)** | 將URI編譯為ASCII碼 | | **decodeURI(X)** | 解析編譯之后的ASCII碼 | # 案例6:使用Math隨機生成一種顏色 ![](https://img.kancloud.cn/9b/23/9b23dd38022f7b24b2899165816bbde3_323x186.png) > 試一試: ![](https://img.kancloud.cn/49/55/49555f65299cd122fefda99f6f3c1a4e_448x112.gif) # 案例7:顯示網頁時鐘 ![](https://img.kancloud.cn/e7/68/e768df2211a74eb19cf7f9a5403aaa5a_412x182.gif) > 注意:日期不足兩位,前面補0 ## 知識點1:Date初始化 ![](https://img.kancloud.cn/d7/39/d7395b4df74589d5bdf4396cf8463061_859x282.png) ## 知識點2:常用方法Date() ![](https://img.kancloud.cn/d8/a7/d8a714cd3660c9486e8690ca274f2935_674x673.png) # 案例8:驗證用戶名 > 規則:字母開頭,包含字母、數字、下劃線長度為4-16位。 ![](https://img.kancloud.cn/99/cd/99cd4519db7b7bb0cd7ca4909534f73d_342x206.png) ## 知識點:正則表達式創建與驗證 ``` var reg = new RegExp(); reg.test(String); ``` > test 檢索字符串中指定的值。返回 true 或 false。 ## 知識點:其他正則表達式方法 > 1. search 檢索與正則表達式相匹配的值。 > 2. match 找到一個或多個正則表達式的匹配。 > 3. replace 替換與正則表達式匹配的子串。 > 4. split 把字符串分割為字符串數組。 ``` var string = new String(); string.search(reg); ``` ## 試一試:驗證手機號 > 規則:以數字1開頭的11位數字。 ![](https://img.kancloud.cn/f2/8c/f28c9b9c6c028fd1f5254fedc8aa4d27_293x203.png) > 規則:以0開頭的3-4位區號+7-8位座機號碼 ![](https://img.kancloud.cn/d9/59/d9595b3f2b139aaae252ff5951421342_339x206.png) ## 試一試:驗證銀行金額 1. 整數部分不超過15位; 2. 數字不能以0開頭,除非整數部分就是0; 2. 可以有小數也可以沒有小數; 3. 小數部分最多兩位。 ## 試一試:金額轉換 ![](https://img.kancloud.cn/a5/bb/a5bbfeeec0fbcafc85eb3c0ce3780cb2_372x152.png) ## 總結: undefined出現的情況 ![](https://img.kancloud.cn/e3/dd/e3dd98d507cc81e6fac0a8cd75d280b1_347x540.png)
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看