yhdsir

怎么在js里写html

<html>
<head>
  <meta charset="utf-8"/>
  <title>示例前端模板写在代码里</title>
</head>
<body>
  <div id="panel"></div>
  <script>
void function() {
  function format(template, json) {
    return template.replace(/#\{(.*?)\}/g, function(all, key) {
      return json && (key in json) ? json[key] : "";
    });
  }
  document.getElementById(\'panel\').innerHTML = format(
    String(function(){/*!
<ul>
    <li>#{title} -- #{date}</li>
    <li>把模板放在注释里</li>
    <li>这样就可以写多行了。。。</li>
</ul>
*/}).replace(/^[^\{]*\{\s*\/\*!?|\*\/[;|\s]*\}$/g, \'\'),
    {
      title: "代码里的模板",
      date: "2014-05-16"
    }
  );
}();
  </script>
  </body>
</html>

 

分类:

技术点:

相关文章:

  • 2022-12-23
  • 2021-12-26
  • 2021-09-14
  • 2022-02-02
  • 2021-10-02
  • 2022-12-23
  • 2021-10-18
猜你喜欢
  • 2021-07-02
  • 2022-12-23
  • 2022-01-02
  • 2021-11-13
  • 2022-12-23
相关资源
相似解决方案