⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 script.js

📁 实现了基本的oa功能:个人日志。。。
💻 JS
📖 第 1 页 / 共 5 页
字号:
        {
           if ((strValue == "") || (strValue == null))
              strValue=strText;
       var oOption;
           oOption = document.createElement("OPTION");
           oOption.text=strText;
           oOption.value=strValue;
           return oOption;
        }

  /**
  * Create an option
  * @param strText the text of the option
  * @param strValue the value of the option
  * @author liuhey
  * @date 2003.3.6
  */
 function swapAllItems(listBoxFrom, listBoxTo)
    {
     if ( (listBoxFrom == null) || (listBoxTo == null) )
             return;

      for (i=0; i < listBoxFrom.options.length;i++)
         listBoxFrom.options[i].selected=true;

         swapItems(listBoxFrom, listBoxTo);
    }
  /**
  * swap the selected options of the listBoxFrom to listBox to
  * @param strText the text of the option
  * @param strValue the value of the option
  * @author liuhey
  * @date 2003.3.6
  */
 function swapItems(listBoxFrom, listBoxTo)
        {
          if ( (listBoxFrom == null) || (listBoxTo == null) || (listBoxFrom.options.selectedIndex == -1) )
             return;

      if (listBoxFrom.options[listBoxFrom.options.selectedIndex].value == "LOADING")   // Don't allow items to be swapped while "Loading"
          return;

          if (listBoxFrom.options.length != 0)
          {
            var lastSelected=-1;
            var count=0;
            var optionsArray=new Array();

                for(i=listBoxFrom.options.length-1;i>=0;i--)
                {
                  if ( (listBoxFrom.options[i].selected==true) || (listBoxFrom.options[i].selected=="true") )
                  {
                        var oOption=createOption(listBoxFrom.options[i].text,listBoxFrom.options[i].value);
                        oOption.selected=true;

                        optionsArray[count]=oOption;
                        count=count+1;
                        listBoxFrom.remove(i);

                        lastSelected=i;
                  }
            }

                // Preserve Order; Add Back In Reverse
                for (i=count; i>0;i--)
                   listBoxTo.add(optionsArray[i-1]);

            if (lastSelected == listBoxFrom.options.length)
                   lastSelected -= 1;

            if (lastSelected >= 0)
                   listBoxFrom.options[lastSelected].selected=true;
          }
        }
    function autoDisplayContent(){
       if(window.parent.displayContent==null){
           if(window.opener.displayContent==null){
               alert("Can't find the method displayContent");
           }else{
               window.opener.displayContent(CenterContent.innerHTML);
               window.close();
           }
       }else{
            window.parent.displayContent(CenterContent.innerHTML);
       }
    }

    function displayHeader(onLineUser, totalUser, time){
        if (window.actualTimeout !=null){
            window.displayTotalUser.innerText = totalUser;
            window.displayOnLineUser.innerText = onLineUser;
            window.actualTimeout.innerText = time;
        }
        if (window.parent !=null && window.parent.actualTimeout !=null){
            window.parent.displayTotalUser.innerText = totalUser;
            window.parent.displayOnLineUser.innerText = onLineUser;
            window.parent.actualTimeout.innerText = time;
        }
        if (window.opener !=null && window.opener.actualTimeout !=null){
            window.opener.displayTotalUser.innerText = totalUser;
            window.opener.displayOnLineUser.innerText = onLineUser;
            window.opener.actualTimeout.innerText = time;
        }
    }

  /**
  * compare the startDate and the endDate
  * @param startDate  the string of the startDate
  * @param endDate the string of the endDate
  * @return true  if startDate>endDate  else return false
  * @author liuhey
  * @date 2003.3.6
  */
    function isDateGreater(startDate,endDate){
       var first = new Date();
       var end = new Date();
       var fullYear = new String(startDate).split("-");
       first.setFullYear(fullYear[0],fullYear[1],fullYear[2]);
       fullYear = new String(endDate).split("-");
       end.setFullYear(fullYear[0],fullYear[1],fullYear[2]);
       if(first.valueOf()>end.valueOf()){
            return true;
         }else{
            return false;
       }

    }

  /**
  * 判断date是否为正确的日期类型值
  * @param date    需要判断的日期类型值
  * @param hint    正确格式应该是yyyy-mm-dd, 例如: 2000-01-01
  * @param hint1   年份应该为一个正整数
  * @param hint2   月份应该为1-12之间的一个正整数
  * @param hint3   日期应该为1到当月最大天数之间的一个正整数
  * @return true    if date is right; false otherwise
  * @author yangc
  * @date 2003.4.20
  */
  function isDateByHint(date, hint, hint1, hint2, hint3) {

    if(!isPatternDate(date)) {
      alert(hint);
      return false;
    }

    return isRightDate(getDateArray(date), hint1, hint2, hint3);
  }

  /**
  * 判断date是否为满足日期类型值的约束
  * @param date    需要判断的日期类型值
  * @return true    if date is right; false otherwise
  * @author yangc
  * @date 2003.4.20
  */
  function isPatternDate(date) {

    var dat = trim(date + "");
    var datePattern = new RegExp("^\\d+-(0?\\d|1[0-2])-([0-2]?\\d|3[0-1])$","g");
    return dat.match(datePattern) == dat;
  }

  /**
  * 判断date是否为正确的日期类型值
  * @param date    需要判断的日期类型值
  * @param hint1   年份应该为一个正整数
  * @param hint2   月份应该为1-12之间的一个正整数
  * @param hint3   日期应该为1到当月最大天数之间的一个正整数
  * @return true    if date is right; false otherwise
  * @author yangc
  * @date 2003.4.20
  */
  function isRightDate(dateArray, hint1, hint2, hint3)
  {
    var day=[31,(dateArray[0]%4==0 && dateArray[0]%100!=0 || dateArray[0]%400==0)?29:28,31,30,31,30,31,31,30,31,30,31];
    if (isNaN(dateArray[0]) || ((dateArray[0] - 0) <= 0))
    {
        alert(hint1);
        return false;
    }
    if (isNaN(dateArray[1]) || ((dateArray[1] - 0) <= 0) || ((dateArray[1] - 12) > 0))
    {
        alert(hint2);
        return false;
    }
    var Max = day[dateArray[1] - 1];
    if (isNaN(dateArray[2]) || ((dateArray[2] - 0) <= 0) || ((dateArray[2] - Max - 0) > 0))
    {
        alert(hint3);
        return false;
    }

    return true;
  }

  /**
  * get the array from date
  * @param date  the string of the Date
  * @return dateArray    type of Array
  * @author yangc
  * @date 2003.4.20
  */
  function getDateArray(date) {

  /*
    var dateArray = new Array();
    dateArray[0] = date.substring(0, date.indexOf("-"));
    date = date.substring(date.indexOf("-") + 1);
    dateArray[1] = date.substring(0, date.indexOf("-"));
    dateArray[2] = date.substring(date.indexOf("-") + 1);
  */
    var dateArray = new String(date).split("-");
    return dateArray;
  }

  /**
  * compare the dateArray1 and the dateArray2
  * @param dateArray1  the array of the date
  * @param dateArray2 the array of the date
  * @return 1    if (dateArray1 > dateArray2)
  * @return 0    if (dateArray1 = dateArray2)
  * @return -1   if (dateArray1 < dateArray2)
  * @author yangc
  * @date 2003.4.20
  */
  function dateCompare(dateArray1, dateArray2) {

    /*
    if (dateArray1[0]*1 > dateArray2[0]*1)
      return 1;
    else if (dateArray1[0]*1 < dateArray2[0]*1)
      return -1;
    else if (dateArray1[1]*1 > dateArray2[1]*1)
      return 1;
    else if (dateArray1[1]*1 < dateArray2[1]*1)
      return -1;
    else if (dateArray1[2]*1 > dateArray2[2]*1)
      return 1;
    else if (dateArray1[2]*1 < dateArray2[2]*1)
      return -1;
    */
    var date_1 = new Date();
    var date_2 = new Date();
    date_1.setFullYear(dateArray1[0], dateArray1[1], dateArray1[2]);
    date_2.setFullYear(dateArray2[0], dateArray2[1], dateArray2[2]);
    if (date_1.valueOf() > date_2.valueOf()) return 1;
    else if (date_1.valueOf() < date_2.valueOf()) return -1;

    return 0;
  }

    /**
     * Remove leading or trailing white space.
     * @add by zhaochao
     */
    function trim(s) {
        var whtSpEnds = new RegExp("^\\s*|\\s*$", "g");
        return s.replace(whtSpEnds, "");
    }


    /**
     * util method to remove all option of a select element
     * @add by liu.dq
     */
    function removeAllOption(select){
        if( select==null)
            return;

        var i = select.options.length;
        while( i>0 ){
           select.options.remove(i-1);
           i--;
        }
    }


    /**
     * util method to add a option to a select element
     * @add by liu.dq
     */
    function addOption(select,value,label){
        if( select==null )
            return ;

        var option = document.createElement("OPTION");
        select.options.add(option);
        option.innerText = label;
        option.value = value;
    }

    /**
     *  util method select all the option
     * @add by liu.dq
     */
    function selectAllOption(select){
        var i;
        for(i=0;i<select.options.length;i++)
            select.options[i].selected=true;
    }

    /**
     * util method to set the option's selected property true whose value is equal "value"
     * @add by liu.dq
     */
    function setSelectedByValue(select,value){
       if( select==null )
          return ;

       for(var i=0;i<select.options.length;i++){
           if(select.options[i].value==value)
               select.options[i].selected = true;
           else
               select.options[i].selected = false;
        }
    }

    /**
     * if date1>date2 return 1, if date1=date2 return 0; if date1<date2 return -1;
     * date format is YYYY-MM-DD
     * this is simple implement!
     */
    function compareDate(date1,date2){
        if( date1>date2 )
           return 1;
        if( date1==date2 )
           return 0;
        if( date1<date2 )
           return -1;
    }

    /**
     *  get the current time and return a string as style yyyy-mm-dd
     * @add by liyh
     */
    function getCurrentDate(){
        var date = new Date();
        date = scriptDateToStr(date);
        return date;
    }

    /**
     *  get the current time and return a string as style yyyy-mm-dd
     * @add by liyh
     */
    function getLastMonth(date){
        var time_array = date.split("-");
        var time = new Date(parseInt(time_array[0], 10), parseInt(time_array[1], 10) - 2, parseInt(time_array[2], 10));
        time = scriptDateToStr(time);
        return time;
    }

    /**
     *  translate javascript date to yyyy-mm-dd style
     * @add by liyh
     */
    function scriptDateToStr(date){
        var timeStr = date.getFullYear();
        if (date.getMonth() > 8)
            timeStr += "-" + (date.getMonth() + 1);
        else
            timeStr += "-0" + (date.getMonth() + 1);
        if (date.getDate() > 9)
            timeStr += "-" + date.getDate();
        else
            timeStr =timeStr + "-0" + date.getDate();
        return (timeStr);
    }

    /**
     *  translate date to yyyy-mm-dd style
     * @add by liyh
     */
    function dateToStr(date){
        var timeStr = date.getFullYear();
        if (date.getMonth() > 9)
            timeStr += "-" + date.getMonth();
        else
            timeStr += "-0" + date.getMonth();
        if (date.getDate() > 9)
            timeStr += "-" + date.getDate();
        else
            timeStr =timeStr + "-0" + date.getDate();
        return (timeStr);
    }

    /**
     * get the current dateTime string,format is yyyy-mm-dd hh-mm-ss
     */
    function getCurrentDateTime(){
        var str = getCurrentDate() + " ";
        var d = new Date();

        if( d.getHours()<=9 )
            str += "0" ;
        str += d.getHours() + ":";
        if( d.getMinutes()<=9 )
            str += "0" ;
        str += d.getMinutes() + ":";
        if( d.getSeconds()<=9 )
            str += "0";

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -