文章来源:http://www.imtr.cn/html/n35.html
织梦的自定义表单是很不错的功能,可以开发为在线留言、在线报名、用户反馈信息等等功能。可是我们想要用到用户提交时间的时候就麻烦了,织梦本身时间标签提交之后时间会自动转换为时间戳,也就是一大串我们压根就看不懂的奇怪数字。如果想要把这一串数字转换为正常时间的话,需要我们修改很多地方的代码,而这对于新手站长来说无疑是个大难题。
小编在这里为大家提供一个取巧的方法,我们在自定义表单中新增一个字段,选择为单行文本。
接下来只需在相关模板的最底部插入一段代码即可轻松显示正常时间了,代码如下:
<script language="javascript" type="text/javascript"> var initializationTime = (new Date()).getTime(); function showLeftTime() { var now = new Date(); var year = now.getFullYear(); var month = now.getMonth()+1; if(month<10) month = '0' + month; var day = now.getDate(); if(day<10) day = '0' + day; var hours = now.getHours(); if(hours<10) hours = '0' + hours; var minutes = now.getMinutes(); if(minutes<10) minutes = '0' + minutes; var seconds = now.getSeconds(); if(seconds<10) seconds = '0' + seconds; var time_str = + year + "年" + month + "月" + day + "日 " + hours + ":" + minutes + ":" + seconds + ""; document.getElementById('input_show').value=time_str; var timeID = setTimeout(showLeftTime, 1000); } </script>
然后我们在页面body的里加入一段代码:onLoad="showLeftTime()"。就像这样:
<body onLoad="showLeftTime()">
接着我们在表单from相关的input中加入id属性 id='input_show'
<input type="text" id="input_show" name="表单中时间字段的名称" value=""/>
OK,是不是很简单,这样的方法可以运用到页面任何地方哦。
效果演示:
原文地址:http://www.imtr.cn/html/n35.html