JavaScript獲取當前根目錄

2021-08-17 11:14:56 字數 737 閱讀 2894

主要用到location 物件,包含有關當前 url 的資訊,是 window 物件的乙個部分,可通過 window.location 屬性來訪問。

方法一 (window.document.location.href/window.document.location.pathname) ------------**網路

function

getrootpath_web()

方法二(window.location.pathname/window.location.protocol/window.location.host)

function

getrootpath_dc()

else

}

注:

1、document默示的是乙個文件物件,window默示的是乙個視窗物件,乙個視窗下可以有多個文件物件。

所以乙個視窗下只有乙個window.location.href,然則可能有多個document.url、document.location.href------------**網路

2、window.location.href和document.location.href可以被賦值,然後跳轉到其它頁面,document.url只能讀不克不及寫------------**網路

3、location 物件詳細資訊參考w3school 

JavaScript獲取當前系統時間

var mydate new date mydate.getyear 獲取當前年份 2位 mydate.getfullyear 獲取完整的年份 4位,1970 mydate.getmonth 獲取當前月份 0 11,0代表1月 mydate.getdate 獲取當前日 1 31 mydate.get...

JavaScript獲取當前根目錄

主要用到location 物件,包含有關當前 url 的資訊,是 window 物件的乙個部分,可通過 window.location 屬性來訪問。方法一 window.document.location.href window.document.location.pathname 網路 funct...

JavaScript獲取當前日期時間

獲取當前日期時間 獲取當前日期時間 var mydate newdate mydate.tolocaledatestring 獲取當前日期 var mytime mydate.tolocaletimestring 獲取當前時間 mydate.tolocalestring 獲取日期與時間 mydate...