導航:首頁 > 動漫圖片 > js本地圖片路徑怎麼寫

js本地圖片路徑怎麼寫

發布時間:2023-06-07 07:50:49

如何用js怎麼獲取到圖片的相對路徑

javascript中img.src屬性可以獲取到圖片的完整路徑, 相對路徑要通過與相對位置計算得出。計算方法:
先要明確自己的相對位置在哪,這個是需要人為指定的。
核心代碼如下:
var res=document.getElementById("img").src;
var root_href='根目錄路徑';
res=document.getElementById("img").src.replace(root_href,'');
用jquery方法
var res=$("#img").attr("src");
res=res.substring(res.indexOf("根")+2);
更多關於在上傳文件的過程得到完整路徑的方法請參考如下:
file.select();
var res=document.selection.createRange().text;
var res=file.files.item(0).getAsDataURL();
var res=file.value

② 如何通過JS獲取用戶本地圖片路徑

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>get file input full path</title>
<script language='javascript'>
function getFullPath(obj)
{
if(obj)
{
//ie
if (window.navigator.userAgent.indexOf("MSIE")>=1)
{
obj.select();
return document.selection.createRange().text;
}
//firefox
else if(window.navigator.userAgent.indexOf("Firefox")>=1)
{
if(obj.files)
{
return obj.files.item(0).getAsDataURL();
}
return obj.value;
}
return obj.value;
}
}
</script>
</head>
<body>
<input type="file" onchange="document.getElementById('img').src=getFullPath(this);" />
<img id="img" />
</body>
</html>

firefox7+請使用return window.URL.createObjectURL(obj.files.item(0));來獲取地址

閱讀全文

與js本地圖片路徑怎麼寫相關的資料

熱點內容
將圖片覆蓋在文字上 瀏覽:841
單身男生擁抱圖片 瀏覽:849
男型發型圖片 瀏覽:279
女生朋友圈發兩張圖片怎麼回復 瀏覽:62
q版帥氣女生圖片 瀏覽:351
長斑小女孩圖片 瀏覽:160
用女孩圖片做頭像 瀏覽:116
生肖小老虎圖片可愛 瀏覽:71
女孩穿衣服帥氣圖片 瀏覽:799
歐美動漫圖片3d 瀏覽:687
游俠洞黑衣女孩圖片 瀏覽:70
動漫圖片開槍 瀏覽:885
中發大卷燙發齊肩發型圖片 瀏覽:806
猛男生蛋糕圖片大全 瀏覽:918
男生鳥仔圖片 瀏覽:95
大清銅幣二十文真品價格及圖片 瀏覽:941
小紅旗價格及圖片 瀏覽:980
藍天白雲圖片大全高清 瀏覽:985
黑色的小人女孩到媽媽圖片 瀏覽:50
古裝男生圖片大全可愛 瀏覽:412