Blogger Information
Blog 56
fans 1
comment 0
visits 62278
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
模板字面量及模板标签
零龙
Original
961 people have browsed it

模板字面量及模板标签

计算一个长方形的周长,使用模板字面量及模板标签编写
示例

  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>模板字面量及模板标签</title>
  7. </head>
  8. <body>
  9. <script>
  10. let long = 20;
  11. let width = 15;
  12. let num = 2;
  13. let girth = calculateArea`长:${long}cm宽: ${width}cm的长方形计算公式:(长 + 宽) x ${num}周长等于:${(long+width)* num}cm`;
  14. function calculateArea(strings,...values)
  15. {
  16. //console.log(strings);
  17. //console.log(values);
  18. let str = "";
  19. for(let i = 0; i< values.length; i++)
  20. {
  21. str += strings[i];
  22. str += values[i];
  23. }
  24. str += strings[strings.length - 1];
  25. return str;
  26. }
  27. console.log(girth);
  28. </script>
  29. </body>
  30. </html>

示例图:

总结:
在调用的函数中可以嵌套多个字面量,可以将参数拼接,没有在实际的应用中不知道这段代码的用处,我相信在以后的前端编写中一定经常使用。在以前看一些前端代码就看到$(*),还以为是PHP的变量。

Correcting teacher:天蓬老师天蓬老师

Correction status:qualified

Teacher's comments:作业并不完整
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post