ES6 - template string

The simplest syntax template literal is to use backquote ( `) (Tab above the key) to wrap an ordinary string, rather than double or single quotes.

<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>

</head>

<body>
  <div id="template">

  </div>
</body>

<script>
  //变量
  let name = "Nicholas";

  //方法
  function makeUpperCase(word) {
    return word.toUpperCase();
  }

  let element = `
              <div>
                  Hello, ${name}
              </div>
              <ul>
                  <li>1.${makeUpperCase('tell me!')}</li>
                  <li>2.call me!~</li>
              </ul>
              `.trim();

  document.getElementById("template").innerHTML = element;
</script>

</html>

Guess you like

Origin www.cnblogs.com/tangge/p/11980459.html