• EJS基本用法


    1.引入

    <script src="/src/ejs_production.js"></script>
    

    2.模板

    <script id="content" type="text/template">
    
        <div class="form-group col-lg-12">
            <label class="control-label  col-lg-3  text-right">
                [% if ( type == 1 ) { %]
                规格一内容:
                [% } else { %]
                规格二内容:
                [% } %]
            </label>
            <span class="input-group col-lg-8 input-group-option">
                <select name="[%= name %]" id="[% id %]" class="form-control spec_cont" style="position: relative; left:-4px;z-index: 1;border-radius:3px;" aria-describedby="object" multiple="multiple">
                    <option value="0">请选择</option>
                    [% for(var i=0; i<attr_val.length; i++) { %]
                        <option value="[%= attr_val[i].id %]" >[%= attr_val[i].name %]</option>
                    [% } %]
                </select>
            </span>
        </div>
    
    
    </script>
    

    3.引入数据

    $("#spec1").on("change",function(){
                var data = {};
                data.id = 'spec1_cont';
                data.name = 'spec1_cont';
                data.type = 1;
    
                let attr_key_id = $(this).val();
                // 获取规格内容
                $.ajax({
                    type:'POST',
                    url:'get_attr_val',
                    data: {attr_key_id: attr_key_id},
                    dataType:'json',
                    success:function(res){
                        if(res.errno == 0){
                            data.attr_val = res.attr_val;
                            var h = new EJS({element:'content'}).render(data);
                            $('#spec1_div_container').html(h);
                            $('.spec_cont').select2();
                        } else {
                            $('#spec1_div_container').html('');
                        }
                    }
                });
    });
    

    里面有if,有for,有=。基本就够用了!
    下载ejs_production

  • 相关阅读:
    p1373
    考试总结 2018-5-6
    p1044与p1898
    p1905
    p1904 p1903
    p1177
    p1273  日常打表
    p1142
    并查集与并查集模板
    p1265
  • 原文地址:https://www.cnblogs.com/jiqing9006/p/9609097.html
Copyright © 2020-2023  润新知