zoukankan      html  css  js  c++  java
  • js 模板

    <html>
        <head>
            <meta charset="UTF-8">
            <script type="text/javascript" src="../js/jquery-1.8.3.min.js"></script>
            <script type="x-template" id="presentTemplate">
                <table border="1">
                    <tr>
                        <th>赠品名称</th>
                        <th>赠品描述</th>
                    </tr>
                    <tr>
                        <td>[presentName]</td>
                        <td>[presentNote]</td>
                    </tr>    
                </table>
            </script>
            <script text="text/javaScript">
                function myPresent(){
                    // 替换正则表达式
                    var reg = new RegExp("\[([^\[\]]*?)\]", 'igm');
                    // 模板
                    var template = $("#presentTemplate").html();
                    // key和value
                    var keyValue = {
                        presentName : "考拉",
                        presentNote : "好想成为考拉,每天18个小时在睡觉"
                    }
                    // 替换后html
                    var newHtml = template.replace(reg,function(node, key){return keyValue[key];});
                    // 把替换后的html展示在页面
                    $("#presentDiv").html(newHtml);        
                }
                $(function(){            
                    myPresent();
                });
            </script>
        </head>
        <body>
            <div id="presentDiv"></div>
        </body>
    </html>

     备注:type="text/html"和type="x-template"的区别我不知道,但是两者均可

  • 相关阅读:
    elemntui-tab添加图标
    动态添加input,然后获取所有的input框中的值
    jmeter_使用接口传递数据
    python_异常
    python_内置函数和open
    jmeter_安装
    jmeter_使用_设置代理录制脚本
    python_函数
    python_while
    python_if、for
  • 原文地址:https://www.cnblogs.com/pumushan/p/4801251.html
Copyright © 2011-2022 走看看