5_字符型扩展.html 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738
  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. </head>
  8. <body>
  9. <div id="box">
  10. </div>
  11. <script>
  12. var num = 10;
  13. var oBox = document.getElementById("box");
  14. // oBox.innerHTML = "<ul><li class='list-item'>"+ num +"</li><li>b</li><li>c</li></ul>";
  15. //模版字符串 内部不区分单引号双引号 支持换行 使用变量${}
  16. oBox.innerHTML = `<ul class="ul-style" >
  17. <li class='li-style'>${num}</li>
  18. </ul>`
  19. var str = "hello world";
  20. var str2 = "ab"
  21. // console.log(str.includes("w"));
  22. // 判断当前字符串是否以制定的字母开头
  23. // console.log(str.startsWith("he"));
  24. // 判断当前字符串是否以制定的字母结尾
  25. // console.log(str.endsWith("rld"));
  26. // console.log(str2.repeat(3));
  27. // 填充方法,向前填充 接收两个参数第一个代表填充长度(包含原有字符串长度),第二个参数以制定的字符进行填充
  28. console.log(str2.padStart(10,"xy"));
  29. // 填充方法,向后填充 接收两个参数第一个代表填充长度(包含原有字符串长度),第二个参数以制定的字符进行填充
  30. console.log(str2.padEnd(10,"xy"));
  31. </script>
  32. </body>
  33. </html>