如何用js獲取當前時間和ip地址以及當前城市

滄海拾遺qaq發表於2020-08-11
<html>
<head>
<script src="http://pv.sohu.com/cityjson?ie=utf-8"></script>
<script src="/statics/assets/js/jquery.min.js"></script>
</head>
<script>
    //時間設定
    function currentTime(){
        var d=new Date(),str='';
        str+=d.getFullYear()+'年';
        str+=d.getMonth() + 1+'月';
        str+=d.getDate()+'日';
        str+=d.getHours()+'時';
        str+=d.getMinutes()+'分';
        str+= d.getSeconds()+'秒';
        return str;
    }

    //setInterval(function(){$('#time').html(currentTime)},1000);

    function getIp(){
        var ip = returnCitySN['cip'];
        $('#ip').html(ip)

        var city = returnCitySN['cname'];
        $('#city').html(city)

        $('#time').html(currentTime)
    }

    window.onload = getIp;

    //alert(returnCitySN['cip'] + returnCitySN['cname']);
</script>
<body>
你本次登陸時間為<span  class="time"><em id="time"></em></span>,
登陸IP:<span  class="time"><em id="ip"></em></span>,
當前所在城市:<span  class="time"><em id="city"></em></span>
</body>
</html>

相關文章