猿问

template.js如何渲染自定义函数?


在做一个项目,拿到后台传过来的时间戳,已经转换成日期格式了,要如何渲染到页面上?

html:


<time id="delivery_time"></time>

jq:


function changeTime(time) {

    return new Date(parseInt(time) * 1000).toLocaleString().replace(/年|月/g, "-").replace(/日/g, " ");

}

$.ajax({

    type: 'get',

    url: PointUrl + '/index.php?act=member_pointorder&op=order_info',

    data: {

        key: key,

        order_id: getQueryString('point_orderid')

    },

    dataType: 'json',

    success: function(result) {

        checkLogin(result.login);

        var data = result.datas;

        var time = data.order_info.point_addtime;

        var localTime = changeTime(time);

        console.log(localTime);

        //这里可以打印出正确的日期格式

    }

});


一只甜甜圈
浏览 1025回答 1
1回答

BIG阳

$.ajax({&nbsp; &nbsp; type: 'get',&nbsp; &nbsp; url: PointUrl + '/index.php?act=member_pointorder&op=order_info',&nbsp; &nbsp; data: {&nbsp; &nbsp; &nbsp; &nbsp; key: key,&nbsp; &nbsp; &nbsp; &nbsp; order_id: getQueryString('point_orderid')&nbsp; &nbsp; },&nbsp; &nbsp; dataType: 'json',&nbsp; &nbsp; success: function(result) {&nbsp; &nbsp; &nbsp; &nbsp; checkLogin(result.login);&nbsp; &nbsp; &nbsp; &nbsp; var data = result.datas;&nbsp; &nbsp; &nbsp; &nbsp; var time = data.order_info.point_addtime;&nbsp; &nbsp; &nbsp; &nbsp; var localTime = changeTime(time);&nbsp; &nbsp; &nbsp; &nbsp; console.log(localTime);&nbsp; &nbsp; &nbsp; &nbsp; //这里可以打印出正确的日期格式&nbsp; &nbsp; &nbsp; &nbsp; document.getElementById('delivery_time').innerHTML=localTime;//显示到节点里&nbsp; &nbsp; }});
随时随地看视频慕课网APP

相关分类

JavaScript
我要回答