zoukankan      html  css  js  c++  java
  • 解决一个难题,值得做一下笔记

     首先我用了一个定时器。

    <script type="text/javascript">
      $(document).ready(function(){
        //循环执行,每隔1秒钟执行一次 1000 
        var t1=window.setInterval(refreshCount, 1000);
        function refreshCount() {
          console.log("ready");
        }
        //去掉定时器的方法  
        window.clearInterval(t1);   
     }); 
    </script>

    然后我在生成表格的时候,然后用for循环加个i做了一个标记,对from的input和day的input框。

    然后我定义了一个数组

    var a = new Array();

    把 i 放到数组里面进去了。点add的时候就push i ,点delete的时候就 pop;

    因为这个是多个的,没办法实时的监听各个表单的id,只能用定时器了

    $(function () {
        var t1=window.setInterval(setValue, 2000);
        function setValue (){
            if (a.length>0){
                for (var j=0;j<a.length;j++){
                    var from = "from";
                    var day = "day";
                    var fromId = from+a[j]+"";
                    var dayId = day+a[j]+"";
                    console.log(fromId);
                    var fromValue = $("#"+fromId).val();
                    if (fromValue!="" || fromValue!=null){
                        $("#"+dayId).val(formatWeek(fromValue));
                    }
                }
            }
        }
    });

    然后再把那个转换星期的方法贴一下。

    function formatWeek(day){
        var day = new Date(day).getDay(),
            text = "";
        switch (day) {
            case 0:
                text = "星期日";
                break;
            case 1:
                text = "星期一";
                break;
            case 2:
                text = "星期二";
                break;
            case 3:
                text = "星期三";
                break;
            case 4:
                text = "星期四";
                break;
            case 5:
                text = "星期五";
                break;
            case 6:
                text = "星期六";
                break;
        }
        return text;
    }
  • 相关阅读:
    codeforces 980A Links and Pearls
    zoj 3640 Help Me Escape
    sgu 495 Kids and Prizes
    poj 3071 Football
    hdu 3853 LOOPS
    hdu 4035 Maze
    hdu 4405 Aeroplane chess
    poj 2096 Collecting Bugs
    scu 4444 Travel
    zoj 3870 Team Formation
  • 原文地址:https://www.cnblogs.com/fuckingPangzi/p/10110071.html
Copyright © 2011-2022 走看看