html獲取本地文件路徑 html頁面中怎么獲取項目根目錄,及引入js和css?
html頁面中怎么獲取項目根目錄,及引入js和css?CSS的介紹方法:。/JS獲取項目的根路徑,例如:http://localhost:8080/ems通用電氣TrotPath:函數(shù)(){//獲取當
html頁面中怎么獲取項目根目錄,及引入js和css?
CSS的介紹方法:。/JS獲取項目的根路徑,例如:http://localhost:8080/ems
通用電氣TrotPath:函數(shù)(){
//獲取當前網(wǎng)址,如:http://localhost:8080/ems/頁/基本/個人.jsp
var curWwwPath=window.document.location文件.href
//獲取主機地址后的目錄,例如:/ems/pages/basic/個人.jsp
變量路徑名=window.document.location文件.pathname
變量位置=curWwwPath.indexOf(路徑名)
//獲取主機地址,例如:http://localhost:8080
變量localhostPath=curWwwPath.substring(0,POS)
//獲取帶有“/”的項目名稱,例如:/ems
var ProjectName=路徑名.子字符串(0, 路徑名.substr(1) .indexof(“/”)1)
本地的html怎么直接通過路徑就讀取本地文件?
要導入圖片,可以導入圖片<img class=“setimg”Src=“a.jpg”alt=“> Src是要引入的本地圖片的相對路徑,即,相對于你的HTML文件,它在哪里,如果它在同一個文件夾中,它可以直接引用像我一樣。如果您在上一個目錄中,請?zhí)砑印?/a.jpg”,然后添加“../”。CSS的引入類似于JS文件,但是標簽不同。CSS的引入使用了<link rel=“stylesheet”href=“>js,和<script> label
第一種類型:file f=new file(這個.getClass().getResource(“/”).getPath())系統(tǒng)輸出打?。╢) 結(jié)果:C:documents and settingsadministratorworkspaceprojectnamebin如果不添加“/”file f=new file(這個.getClass().getResource(“”).getPath())系統(tǒng)輸出打印(f) 結(jié)果:C:documents and settingsadministratorworkspaceprojectnamebincomtest獲取當前類的絕對路徑;第二種類型:file directory=new file(“)//參數(shù)為空字符串=目錄.getCanonicalPath() 系統(tǒng)輸出打印(coursefile)結(jié)果:C:documents and settingsadministratorworkspaceprojectname獲取當前類所在的第三個項目路徑:URL xmlpath=這個.getClass().getClassLoader().getResource() 選定.txt") 系統(tǒng)輸出打?。▁mlpath)結(jié)果:文件:/c:/documents and Settings/Administrator/workspace/projectName/bin/選定.txt獲取當前項目SRC目錄選定.txt文件的路徑