7_字符串扩展.html 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <title>Document</title>
  7. <style>
  8. .box{
  9. color: red;
  10. }
  11. </style>
  12. </head>
  13. <body>
  14. <ul>
  15. </ul>
  16. <button>添加</button>
  17. <script>
  18. // let ul = document.querySelector("ul");
  19. // let btn = document.querySelector("button");
  20. // var i = 1;
  21. // btn.onclick = function(){
  22. // // ul.innerHTML += "<li class='box'>"+(i++)+"</li>";
  23. // ul.innerHTML += `<li class="box">${i++}</li>`
  24. // }
  25. // 模版字符串
  26. // 定义方式为:``
  27. // 1、模版字符串内可以任意使用引号
  28. // 2、模版字符串内可以换行
  29. // 3、模版字符串内可以使用变量 ${变量}
  30. // includes 判断字符串中是否办函子串
  31. // let str = "hello";
  32. // console.log(str.includes("e"));
  33. // startsWidth 判断字符串是否以指定的子串为开头
  34. // let str = "hello";
  35. // console.log(str.startsWith("e"));
  36. // endsWidth 判断字符串是否以指定的子串为结尾
  37. // let str = "hello";
  38. // console.log(str.endsWith("o"));
  39. // repeat 字符串重复指定次数
  40. // let str = "hello";
  41. // console.log(str.repeat(3));
  42. // padStart 以指定的字符开头扩展字符串
  43. // let str = "hello";
  44. // console.log(str.padStart(10,"x"));
  45. // padEnd 以指定的字符结尾扩展字符串
  46. // let str = "hello";
  47. // console.log(str.padEnd(10,"x"));
  48. // trim() 去掉字符串首尾的空格
  49. // trimStart()去除开头的空格
  50. // let str = " hello";
  51. // console.log(str.trimStart());
  52. // trimEnd()去除结尾空格
  53. // let str = "hello ";
  54. // console.log(str.trimEnd());
  55. // at()获取指定位置的字符
  56. // let str = "hello";
  57. // console.log(str.at(0));
  58. </script>
  59. </body>
  60. </html>