zoukankan      html  css  js  c++  java
  • 服务器端获取客户端信息(时间 etc..)

    能在client端写JavaScript,就尽量在客户端写。

    格式化时间:

    代码
        <script language="javascript" type="text/javascript">
            
    function formatWithZero(nValue) {
                
    if (nValue < 10) nValue = "0" + nValue;
                
    return nValue; 
             }
        
    </script>

    ServerSide:

    代码
            //Register clientjs and hiddenfield to get client time with format "yyyy/MM/dd hh:mm:ss"
            private const string CLIENTTIME_SCRIPT_ID = "__CLIENTTIMEJS";
            
    private const string CLIENTTIME_FIELD = "__CLIENTTIME";
            
    private string ClientTime
            {
                
    get
                {
                    
    return this.Request.Form[CLIENTTIME_FIELD];
                }
            }
            
    protected override void OnLoad(EventArgs e)
            {
                ClientScript.RegisterHiddenField(CLIENTTIME_FIELD, 
    "");

                
    if (!ClientScript.IsOnSubmitStatementRegistered(typeof(string), CLIENTTIME_SCRIPT_ID))
                {
                    ClientScript.RegisterOnSubmitStatement(
    typeof(string),
                        CLIENTTIME_SCRIPT_ID, 
    "var today = new Date();var year =today.getFullYear();var month =today.getMonth()+1;" +
                        
    "var day = today.getDate();var hours=today.getHours();var minutes=today.getMinutes();var seconds=today.getSeconds();" +
                        
    "document.getElementById('" +
                        CLIENTTIME_FIELD 
    + "').value=year+'/'+formatWithZero(month)+'/'+formatWithZero(day)+' '+formatWithZero(hours)+':'+formatWithZero(minutes)+':'+formatWithZero(seconds)");
                }

                
    base.OnLoad(e);
            }
  • 相关阅读:
    求教——使用node做表单,刷新浏览器页面,浏览器为什么会重复提交上次所填的信息
    sublime 插件
    h5专题应该兼容那些浏览器?
    省市区县镇级联数据JS版
    使用 iscroll 实现焦点图无限循环
    DAO与DTO的区别
    Struts2的DMI的开启方法
    在JSP中的java代码中调用js代码
    Eclipse发布web项目时报错:Multiple Contexts have a path of "/xxx".
    记录:将MyEclipse的Dynamic Web Project项目部署到Eclipse的过程
  • 原文地址:https://www.cnblogs.com/xixifusigao/p/1855664.html
Copyright © 2011-2022 走看看