zoukankan      html  css  js  c++  java
  • js中字符串的拼接的另一种方法

    // 按一定长度截断字符串,并使用 + 运算符进行连接。
    // 分隔字符串尽量按语义进行,如不要在一个完整的名词中间断开。
    // 特别的,对于HTML片段的拼接,通过缩进,保持和HTML相同的结构。
    var html = '' // 此处用一个空字符串,以便整个HTML片段都在新行严格对齐
        + '<article>'
        +     '<h1>Title here</h1>'
        +     '<p>This is a paragraph</p>'
        +     '<footer>Complete</footer>'
        + '</article>';
    
    // 也可使用数组来进行拼接,相对 + 更容易调整缩进。
    var html = [
        '<article>',
            '<h1>Title here</h1>',
            '<p>This is a paragraph</p>',
            '<footer>Complete</footer>',
        '</article>'
    ];
    html = html.join('');
  • 相关阅读:
    面向对象之prototype,__proto__
    Screen对象
    location对象
    history对象
    JS计时器
    window对象
    Dom操作html详细
    终端 git log 修改样式
    null 和 NULL 判断
    textfield设置左边距
  • 原文地址:https://www.cnblogs.com/smile-ls/p/4683372.html
Copyright © 2011-2022 走看看