String_JavaScript 桃扇骨 2024-03-31 12:58 23阅读 0赞 ## String\_JavaScript ## **学习路线**:[JavaScript基础语法(输出语句)][JavaScript]\->[JavaScript基础语法(变量)][JavaScript 1]\->[JavaScript基础语法(数据类型)][JavaScript 2]\->[JavaScript基础语法(运算符)][JavaScript 3]\->[JavaScript基础语法(流程控制语句)][JavaScript 4]\->[JavaScript基础语法(类型转换)][JavaScript 5]\->[JavaScript基础语法(函数)][JavaScript 6]\->[Array\_JavaScript][Array_JavaScript]\->[String\_JavaScript][String_JavaScript]\->[自定义对象\_JavaScript][JavaScript 7]\->[JavaScript\_BOM][JavaScript_BOM]\->[Window对象][Window]\->[confirm()、setInterval()、setTimeout()][confirm_setInterval_setTimeout]\->[History、Location][History_Location]\->[闪烁的灯泡][Link 1]\->[JavaScript\_DOM][JavaScript_DOM]\->[事件绑定(onclick,onfocus,onblur)][onclick_onfocus_onblur]\-> [事件绑定(onmouseout,onmouseover) ][onmouseout_onmouseover_]\->[事件绑定(onsubmit)表单提交 ][onsubmit_]\->[提交表单与验证表单案例 ][Link 2] **简介**:String对象。 [官方文档][Link 3] 创建方式 * 方式1: var 变量名 = new String(s); * 方式2: var 变量名 = "数组"; **属性:** String对象提供了很多属性,属性 `length`特别常用 ,该属性是用于动态的获取字符串的长度 ![在这里插入图片描述][3039e94f863a49cda1fbbf1579cebe4a.png] **函数:** String常用的函数 ![在这里插入图片描述][28a9d3dfec4f4706a6c7a2225aa50f6c.png] **遍历方法** <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> </head> <body> <script> var str = "abc" for(var i = 0; i < str.length; ++ i){ console.log(str.charAt(i)) } </script> </body> </html> **`tirm()`:去掉两边空格** 代码演示: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> </head> <body> <script> var str4 = ' abc '; alert(str4.trim()); </script> </body> </html> **运行结果** ![在这里插入图片描述][777e63b098094c80b5bbc87d0056ac43.png] `trim()` 函数在以后开发中还是比较常用的,例如登录页面 ![在这里插入图片描述][7192d82a101745ac8ea4e38ac2db50fc.png] [JavaScript]: https://blog.csdn.net/qq_51447496/article/details/128085137 [JavaScript 1]: https://blog.csdn.net/qq_51447496/article/details/128085348 [JavaScript 2]: https://blog.csdn.net/qq_51447496/article/details/128086148 [JavaScript 3]: https://blog.csdn.net/qq_51447496/article/details/128086681 [JavaScript 4]: https://blog.csdn.net/qq_51447496/article/details/128088817 [JavaScript 5]: https://blog.csdn.net/qq_51447496/article/details/128087248 [JavaScript 6]: https://blog.csdn.net/qq_51447496/article/details/128088986 [Array_JavaScript]: https://blog.csdn.net/qq_51447496/article/details/128089474 [String_JavaScript]: https://blog.csdn.net/qq_51447496/article/details/128089631 [JavaScript 7]: https://blog.csdn.net/qq_51447496/article/details/128089766 [JavaScript_BOM]: https://editor.csdn.net/md/?articleId=128095193 [Window]: https://blog.csdn.net/qq_51447496/article/details/128095300 [confirm_setInterval_setTimeout]: https://blog.csdn.net/qq_51447496/article/details/128103458 [History_Location]: https://blog.csdn.net/qq_51447496/article/details/128104240 [Link 1]: https://blog.csdn.net/qq_51447496/article/details/128095524 [JavaScript_DOM]: https://blog.csdn.net/qq_51447496/article/details/128104720 [onclick_onfocus_onblur]: https://blog.csdn.net/qq_51447496/article/details/128110532 [onmouseout_onmouseover_]: https://blog.csdn.net/qq_51447496/article/details/128112439 [onsubmit_]: https://blog.csdn.net/qq_51447496/article/details/128112553 [Link 2]: https://blog.csdn.net/qq_51447496/article/details/128112770 [Link 3]: https://www.w3school.com.cn/jsref/jsref_obj_string.asp [3039e94f863a49cda1fbbf1579cebe4a.png]: https://image.dandelioncloud.cn/pgy_files/images/2024/03/31/c9550feec68c4851b80b0ac2afc87f4b.png [28a9d3dfec4f4706a6c7a2225aa50f6c.png]: https://image.dandelioncloud.cn/pgy_files/images/2024/03/31/8a3268c8683f491a88439748f30272b8.png [777e63b098094c80b5bbc87d0056ac43.png]: https://image.dandelioncloud.cn/pgy_files/images/2024/03/31/f594010aeefc46ba9bbfc9d3064fbe51.png [7192d82a101745ac8ea4e38ac2db50fc.png]: https://image.dandelioncloud.cn/pgy_files/images/2024/03/31/343a88a4f8034043a1f5a4be063bdcb8.png
还没有评论,来说两句吧...