使用javascript 模板引擎artTemplate 出现template undefined的现象
PHP中文网
PHP中文网 2017-04-10 16:49:41
0
1
111
<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <meta name="format-detection" content="telephone=no" />
    <meta name="viewport" content="width=device-width,initial-scale=1.0,user-scalable=no" />
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <script src="../js/jquery-1.9.1.min.js"></script>
    <script src="../js/template-native.js"></script>
    <title>团购首页</title>
</head>
<body>

<!--头部-->
<p class="header w100" >
    <p class="header-cont  pr">
        <p class="header-left-city ">深圳市</p>
        <p class="header-center f36">小区团</p>
        <a href="#" class="header-right  pa" ></a>
    </p>
</p>
<p class="main w100">
    <!--团购活动-->
    <p class="datalist"></p>    
</p>    
<script id="test" type="text/html">
    <% for(var i=0;i!==data.data.length;i++){ console.log(data) %>
    <p class="p20 m20 bgf activity">
        <p class="activity-pic w100"><img src="<%= data.data[i].groupon_img %>" class="w100" height="auto"></p>
        <p class="f28c6 activity-biaoti"><%= data.data[i].name %></p>
        <p class="f28c9 miaoshu  "><%= data.data[i].groupon_desc %></p>
        <p class="activity-ft clearfix bordert">
            <p class="fl">
                <p class="f32cse ">团购:¥<span class="buy_separately"><%= data.data[i].groupon_price %></span>元</p>
                <p class="f24c9 ">单独购买:¥<span class="in_total"><%= data.data[i].price %></span>元</p>
            </p>
            <p class="fr">
                <a href="groupDetails.html" id="btnqiang"><%= data.data[i].groupon_num %>人团,马上抢购&gt</a>
            </p>
        </p>
    </p>
    <% } %>
</script>
<script>
    $.get("../json/index.json",function(data){
        console.log(data);
        if(data.status!==200){
            return false;
        }
    var html = template('test',data);
        $(".datalist").html(html);
    })
</script>


</body>
</html>
PHP中文网
PHP中文网

认证高级PHP讲师

membalas semua(1)
巴扎黑
//将script中含有data,删除一个data,即可以解决该问题,script中代码更改后如上
<script id="test" type="text/html">
    <% for(var i=0;i!==data.length;i++){  %>
    <p class="p20 m20 bgf activity">
        <p class="activity-pic w100"><img src="<%= data[i].groupon_img %>" class="w100" height="auto"></p>
        <p class="f28c6 activity-biaoti"><%=data[i].name %></p>
        <p class="f28c9 miaoshu  "><%= data[i].groupon_desc %></p>
        <p class="activity-ft clearfix bordert">
            <p class="fl">
                <p class="f32cse ">团购:¥<span class="buy_separately"><%= data[i].groupon_price %></span>元</p>
                <p class="f24c9 ">单独购买:¥<span class="in_total"><%= data[i].price %></span>元</p>
            </p>
            <p class="fr">
                <a href="#" id="btnqiang"><%= data[i].groupon_num %>人团,马上抢购&gt</a>
            </p>
        </p>
    </p>
    <% } %>
</script>
<script>
$.get("../json/index.json", function (data) {
    console.log(data);
    if(data.status!==200){
        return false;
    }
    var html = template('test',data);
    $(".datalist").html(html);
})

</script>

Muat turun terkini
Lagi>
kesan web
Kod sumber laman web
Bahan laman web
Templat hujung hadapan