html 表單賦值 和 時間戳 轉換
阿新 • • 發佈:2018-02-12
min return 輸入 cond rip bag val minute onload
<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 表單賦值 和 時間戳 轉換