[英]Javascript Template Literals and Html Textarea
I'd use a separate script file instead, for which no indentation will be needed (or even appropriate) on the top level:我会改用一个单独的脚本文件,在顶层不需要(甚至不需要)缩进:
// script.js
const htmlStr =
`<section>
...
</section>`;
document.getElementById('txtHtmlStr').defaultValue = htmlStr;
<script src="./script.js"></script>
I'd prefer to separate script files from HTML files anyway, they can make things easier (eg, for proper separation of concerns, for having a single entry point, to permit linting, minifying, and transpiling)无论如何,我更愿意将脚本文件与 HTML 文件分开,它们可以使事情变得更容易(例如,为了适当的关注点分离,为了有一个单一的入口点,以允许 linting,缩小和转译)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.