var html="";
html = '<div class="pack-week  margin-bott" style="display: show;">',
html += '<div class="pack-week-fir center">',
html += '<div class="pack-week-tit">',
html += '<div class="pack-week-txt">第二周</div>',
html += '</div>',
html += '<div class="pack-week-type">',
html += '<div class="pack-week-type-tit">蔬菜</div>',
html += '<div id="max1">',
html += '<div id="add-y-btn1" class="add-y-btn">',
html += '<div class="pack-type-ve" >',
html += '<input type="" name="" class="pack-ve-inp" placeholder="请输入">',
html += '<input type="" name="" class="pack-ve-inp" placeholder="请输入">',
html += '<div class="pack-type-fun-btn on-add1 ">',
html += '<i class="icon pack-btn-i op" ></i>',
html += '</div>',
html += '<div class="pack-type-fun-btn cl-btn reee1">',
html += '<a class="icon pack-btn-cl-i"></a>',
html += '</div>',
html += '</div>',
html += '</div>',
html += '</div>',
html += '</div>',
html += '<div class="pack-week-type">',
html += ' <div class="pack-week-type-tit">肉类</div>',
html += '<div id="a1">',
html += '<div id="b1" class="b">',
html += '<div class="pack-type-ve">',
html += '<input type="" name="" class="pack-ve-inp" placeholder="请输入">',
html += '<input type="" name="" class="pack-ve-inp" placeholder="请输入">',
html += '<div class="pack-type-fun-btn on-btn-two1">',
html += '<i class="icon pack-btn-i"></i>',
html += '</div>',
html += '<div class="pack-type-fun-btn cl-btn ree1 " >',
html += '<i class="icon pack-btn-cl-i"></i>',
html += '</div>',
html += '</div>',
html += '</div>',    
html += '</div>',
html += '</div>',
html += '<div class="up-down-week">',
html += '<div class="up-week-btn top">',
html += '<a href="javascript:void(0)">上一周</a>',
html += '</div>',
html += '<div class="up-week-btn down1">',
html += ' <a href="javascript:void(0)">下一周</a>',
html += '</div>',
html += '</div>',
html += '</div>',
html += '<div class="pack-deta-chan">',
html += '<div class="order-fun-item fun-btn-che">',
html += '<a href="">修改商品</a>',
html += '</div>',
html += '</div>',
html += '</div>'

解决方案 »

  1.   


    function fhtml(id) {
    var html="";
    html = '<div class="pack-week  margin-bott" style="display: show;">';
    html += '<div>'+id+'</div>';
    html += '</div>';
    return html;
    }alert(fhtml("123"));
    alert(fhtml("456"));
      

  2.   

    第二种方法 var html="";
    html = '<div class="pack-week  margin-bott" style="display: show;">';
    html += '<div>{{id}}</div>';
    html += '</div>';alert(html.replace("{{id}}","123"));
    alert(html.replace("{{id}}","456"));
      

  3.   

    用vue或者knockoutjs一类的框架,绑定模板