replaceDate : function (date) {
//替换字符时间
var ndate = date.replace(/./g, function (a) {
return dateObject.strDate[a];
}), number = ndate.split("十");
if (number.length == 2) {
number[0] = number[0] || "1";
number[1] = number[1] || "0";
return number.join("");
} else return ndate;
},
修改下这个函数。

解决方案 »

  1.   

    <script type="text/javascript">
    var temp = "";
    function aa(obj)
    {
    var value = obj.value;value = value.replace(/十一/g, "11");
    value = value.replace(/十二/g, "12");
    value = value.replace(/十三/g, "13");
    value = value.replace(/十四/g, "14");
    value = value.replace(/十五/g, "15");
    value = value.replace(/十六/g, "16");
    value = value.replace(/十七/g, "17");
    value = value.replace(/十八/g, "18");
    value = value.replace(/十九/g, "19");
    value = value.replace(/○/g, "0");
    value = value.replace(/零/g, "0");
    value = value.replace(/一/g, "1");
    value = value.replace(/二/g, "2");
    value = value.replace(/三/g, "3");
    value = value.replace(/四/g, "4");
    value = value.replace(/五/g, "5");
    value = value.replace(/六/g, "6");
    value = value.replace(/七/g, "7");
    value = value.replace(/八/g, "8");
    value = value.replace(/九/g, "9");
    value = value.replace(/十/g, "0");
    value = value.replace(/\D/g, "-");
    if(value.substring(value.length - 1, value.length) == "-")
    value = value.substring(0 , value.length - 1);value = value.replace(temp, "");
    temp = value;
    obj.value = value;
    }
    </script>
    <p>
      <input id="a" name="a" type="text" onFocus="javascript:aa(this);">
      <input id="a2" name="a2" type="text" onfocus="javascript:aa(this);" />
      <input id="a3" name="a3" type="text" onfocus="javascript:aa(this);" />
    </p>
    <p>2000.12.11
      </p>
    </p>
    <p>2000/11/12</p>
    <p>2000年11月02</p>
    <p>二二零零年十一月二十日</p>
    <p>二○○六年九月十四日</p>
    <p>二00五年十月十四日</p>
    <p>2000年10月20日
    新年快乐   你看一下这个    当我用鼠标选择二○○六年九月十四日时  复制或者是用鼠标拖到到输入框中后时间格式自动变成2006-09-14    
      

  2.   

    可以试试Regex.execvar xxx = "";
    while(re.exec(string))
    {
    alert(Regex.$0);
    xxx += Regex.$0;
    }
    parseInt(xxx);
      

  3.   

    忽忽,新年快乐,这个是年前,xiaojinyi短消息问我的。。哈哈,假期光从网吧通宵啦今天刚刚回复
      

  4.   

    muxrwc  看到我刚发给你的那个例子了吗? 我想做成那种效果的
    谢谢了
      

  5.   

    to:gzdiablo
    不太明白什么意思
    能具体说下不?to:xiaojinyi
    正是因为感觉查找多次比较麻烦所以才加了
    replaceDate : function (date) {
    //替换字符时间
    var ndate = date.replace(/./g, function (a) {
    return dateObject.strDate[a];
    }), number = ndate.split("十");
    if (number.length == 2) {
    number[0] = number[0] || "1";
    number[1] = number[1] || "0";
    return number.join("");
    } else return ndate;
    },
    这些
    噢。。立即啊?
    不会那个。。不过可以用setInterval之类的控制。。
      

  6.   

    想了想还是有问题
    本来是这样想的re = /./g;
    str = "二零零六";
    xxx = "";
    while(re.exec(str))
    {
    alert(Regex.$0);//这里循环每个匹配 再替换成数字 但想了一下还是上面的方法简单点 虽然写的东西多了点
    }
      

  7.   

    to:xiaojinyi
    我知道你的意思。。你是想当copy到那里或者是拖拽到那里立即触发变换。。
    可是我不知道那样的东西有没有专门的事件。
    用onfocus
    或者onchange这样的效果不行么?to:gzdiablo
    用那个循环的话,到是可以不用套函数。。不过如果要从里面逐个判断的话,那样好麻烦。。还要加标志为(当前是第几个了)
    首先替换全部除了10以外
    想了半天。情况只有三种。。
    一:
    当前面有数的时候10里的1将不需要加。。
    二:
    当后面有数的时候10里的0将不需要加。。
    三:
    没有10^o^所以就写成那样的了
      

  8.   

    对    我也是遇到了   没有10的现象     楼主厉害啊  
    用onfocus  或者onchange如果可以实现那种效果就可以了   不管什么方法只要最终效果是对的就可以 
      

  9.   

    http://community.csdn.net/Expert/topic/5282/5282465.xml?temp=.3733026
      

  10.   

    O_O
    什么意思?
    提交后按后退就不好用了?
    不太明白。。刚测试了以下,没有那种情况啊。。<input id="wc" onchange="this.value = dateObject.formatDateTime(this.value)" />
    这样就可以了。
      

  11.   

    不好实现就算了     还是很谢谢你 
    http://community.csdn.net/Expert/topic/5315/5315255.xml?temp=.3185999你看这个会吗  ?    都是年前留下来的问题      哈哈
      

  12.   

    window.onload = function () {
    var wc1 = $("wc1"), wc2 = $("wc2");
    change(wc1[wc1.selectedIndex]);
    change(wc2[wc2.selectedIndex]);
    };
    加上它就可以保存状态了。。
    <select id="wc1"
    <select id="wc2"
    还要把select元素加上id属性。
      

  13.   

    昂?
    时间格式化那个?
    不冲突吧?
    那个结构体是dateObject.formatDateTime(传过去参数)
    然后返回的就是格式话好的日期。。
    至于具体怎么应用,这个要看你啊。。
    <input onchange="this.value = dateObject.formatDateTime(this.value)" />
    这个是input当发生变化并且失去焦点后。。触发格式化。。
      

  14.   

    其实判断 十 的问题只要判断下 xxx是否为空 就可以了 但感觉满乱的 就不建议用了
      

  15.   

    这个问题以前讨论过,emu有个帖子,地址忘了,代码如下。
    function toCHS(s){return s.constructor!=Number?s.constructor!=String?s.constructor!=Date?null:toCHS(s.getFullYear()+"")+"年"+toCHS(s.getMonth()+1)+"月"+toCHS(s.getDate())+"日"+toCHS(s.getHours())+"时"+toCHS(s.getMinutes())+"分"+toCHS(s.getSeconds())+"秒":s.replace(/\d/g,function(a){return"零一二三四五六七八九".charAt(parseInt(a))}):toCHS(((s>19?Math.floor(s/10):"")+(s>9?("十"):"")+(s%10==0&&s>0?"":s%10)))}
    alert(toCHS(new Date()));
      

  16.   

    敬爱的斑竹哥哥...怎么有人贴广告啊..
    lihong123457
    noahsoft1208
    这两个都是广告,貌似是用专门的软件贴近来的..
      

  17.   

    document.write(toCHS("2000年12月31日"));
    二零零零年一二月三一日
    这个它只是用charAt配合parseInt转换了..
    应该是
    二零零零年十二月三十一日
      

  18.   

    - -
    看错了....那个是数值转汉字.不是string的数值内容转汉字.
      

  19.   

    <script type="text/javascript">
    var dateObject = {
    //不考虑IE5.5以下版本浏览器的话可以写简单一些(目前就是,主要是replace里放函数需要5.5+)
    strDate : {
    //关键字
    "一" : 1, "二" : 2, "三" : 3, "四" : 4, "五" : 5, "六" : 6, "七" : 7, "八" : 8, "九" : 9, "零" : 0, "十" : "十", "○" : 0
    },
    replaceDate : function (date) {
    //替换字符时间
    var ndate = date.replace(/./g, function (a) {
    return dateObject.strDate[a];
    }), number = ndate.split("十");
    return (number.length == 2 ? (number[0] || "1") + (number[1] || "0") : ndate);
    },
    isDate : function (y, m, d) {
    //判断日期是否为有效
    var date, y, m, d;
    date = new Date(y, m - 1, d);
    return (y == date.getFullYear() && m == date.getMonth() + 1 && d == date.getDate());
    }, 
    formatDateTime : function (time) {
    //修改日期格式
    var y, m, d;
    var numDatePattern = /^(\d{4})[\/\.年\-](\d{1,2})[\/\.月\-](\d{1,2})日?$/;
    var strDatePattern = /^([零○一二三四五六七八九十]{4})年([零一二三四五六七八九十]{1,2})月([零一二三四五六七八九十]{1,3})日$/;
    if (numDatePattern.test(time) || strDatePattern.test(time)) {
    y = RegExp.$1, m = RegExp.$2, d = RegExp.$3;
    if (!parseInt(y)) {
    y = dateObject.replaceDate(y);
    m = dateObject.replaceDate(m);
    d = dateObject.replaceDate(d);
    }
    } else return null;
    return (dateObject.isDate(y, m, d) ? y + "-" + (m.length == 2 ? m : "0" + m) + "-" + (d.length == 2 ? d : "0" + d) : null);
    }
    };function show(date_value) {
    //显示结果
    document.write(date_value + "<br \/>修改为:" + dateObject.formatDateTime(date_value) + "<hr \/>");
    }
    show("二零零零年十月三十一日");
    show("二零零零年十一月三十日");
    show("2000/11/12");
    show("2000年11月12日");
    show("2000.11.12");
    show("二零零零年十一月十二日");
    show("二零零零年十月十二日");
    show("二零零零年一月十二日");
    show("二○○一年一月十二日");
    show("2000-1-12");
    </script>
    <input id="wc" onchange="this.value = dateObject.formatDateTime(this.value)" />
    简化了书写...