码迷,mamicode.com
首页 > Web开发 > 详细

html 表单赋值 和 时间戳 转换

时间:2018-02-12 18:55:49      阅读:230      评论:0      收藏:0      [点我收藏+]

标签:load   update   gen   pre   pos   service   script   type   ons   

    <script>
        window.onload = function () {
            var str;
          //  console.log(@ViewBag.ID);
            $.post("/ServiceBills/ServiceBills/UpdateA",
                { id: @ViewBag.ID},
                function (data) {
                    //console.log(data);
                    //console.log("1222222");
                    //$("form").setForm(data);
                    for (var attr in data) {
                        //console.log(attr);//name,age,gender
                       // console.log(data[attr]);//jack,25,male  //值
                        //console.log(typeof json1[attr]);
                        // $("#" + attr).val("111111111");
                     
                        $("#" + attr).val(data[attr]);  //id
                        if ((data[attr] + "").indexOf("/Date(") != -1) {  //时间
                            str = data[attr] + "";
                           
                            str = timestampToTime(str.substring(6, str.length - 2));
                          //  console.log(str);
                        }
                        else {
                            str = data[attr];
                        }
                        $("input[name=‘" + attr + "‘]").val(str); //输入框

                    }                   
                });
           // console.log("12132");

            @*$.post("/ServiceBills/ServiceBills/UpdateA",{ id=@ViewBag.ID},
                function (data) {
                    console.log(data);
                    //$("form").setForm(data);
                });*@
        } 
        function timestampToTime(timestamp) {
            ///Date(1514736000000)/
            var date = new Date(timestamp * 1);//时间戳为10位需*1000,时间戳为13位的话不需乘1000
            Y = date.getFullYear() + ‘-‘;
            M = (date.getMonth() + 1 < 10 ? ‘0‘ + (date.getMonth() + 1) : date.getMonth() + 1) + ‘-‘;
            D = date.getDate() + ‘ ‘;
            h = date.getHours() + ‘:‘;
            m = date.getMinutes() + ‘:‘;
            s = date.getSeconds();
            return Y + M + D + h + m + s;
        }
        //timestampToTime();
        console.log(timestampToTime(1514736000000));//2014-06-18 10:33:24
    </script>

 

html 表单赋值 和 时间戳 转换

标签:load   update   gen   pre   pos   service   script   type   ons   

原文地址:https://www.cnblogs.com/enych/p/8444776.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!