js小函数工具

突然想到建一片文章关于自己所学到的一些小函数,今后需要的时候可以直接当工具使用。

1.获取当前时间小程序。

function showTime(){
        var show_day=new Array('星期一','星期二','星期三','星期四','星期五','星期六','星期日');
        var time=new Date();
        var year=time.getFullYear();
        var month=time.getMonth();
        var date=time.getDate();
        var day=time.getDay();
        var hour=time.getHours();
        var minutes=time.getMinutes();
        var second=time.getSeconds();
        month=month+1;
        hour<10?hour='0'+hour:hour;
        minutes<10?minutes='0'+minutes:minutes;
        second<10?second='0'+second:second;
        var now_time='今天是:'+year+'年'+month+'月'+date+'日'+' '+show_day[day-1]+' '+hour+':'+minutes+':'+second;
        document.getElementById('showtime').innerHTML=now_time;
        setTimeout("showTime();",1000);
      }
      showTime();

2.获取天气预报信息

findWeather();
      function findWeather() {
        var cityUrl = 'http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=js';
        $.getScript(cityUrl, function(script, textStatus, jqXHR) {
          var citytq = remote_ip_info.city ;// 获取城市
          var url = "http://php.weather.sina.com.cn/iframe/index/w_cl.php?code=js&city=" + citytq + "&day=0&dfc=3";
          $.ajax({
            url : url,
            dataType : "script",
            scriptCharset : "gbk",
            success : function(data) {
              var _w = window.SWther.w[citytq][0];
              var _f= _w.f1+"_0.png";
              if(new Date().getHours() > 17){
                _f= _w.f2+"_1.png";
              }
              var img = "<img width='16px' height='16px' src='http://i2.sinaimg.cn/dy/main/weather/weatherplugin/wthIco/20_20/" +_f
                      + "' />";
              var tq = citytq + " " + img + " " + _w.s1 + " " + _w.t1 + "℃~" + _w.t2 + "℃ " + _w.d1 + _w.p1 + "级";

              $('#weather').html(tq);
            }
          });
        });
      }

3.等待更新。。。。

努力吧,为了媳妇儿,为了家。。。
原文地址:https://www.cnblogs.com/jlj9520/p/6264493.html