導航:首頁 > 動漫圖片 > 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本地圖片路徑怎麼寫相關的資料

熱點內容
二年級交通安全小報圖片大全簡單漂亮 瀏覽:765
情侶動漫頭圖片 瀏覽:461
e福州核酸檢測報告圖片怎麼保存 瀏覽:387
汽車圖片怎麼設置方向 瀏覽:384
粉紅頭發動漫少女圖片 瀏覽:741
情頭素描動漫圖片 瀏覽:428
怎樣在word文章中插入圖片 瀏覽:895
該如何下載圖片 瀏覽:963
甩臉給你看的文字和圖片 瀏覽:592
qq男生超帥氣圖片 瀏覽:357
簡單桌面壁紙圖片 瀏覽:368
手機qq圖片和文字怎麼一起發 瀏覽:816
可愛ppt邊框圖片 瀏覽:725
圖片怎麼轉化文字格式 瀏覽:346
鎖骨發發型圖片沒有劉海 瀏覽:211
word文本框不能放圖片嗎 瀏覽:735
昌河Q7圖片及價格 瀏覽:179
自己製作走秀衣服圖片 瀏覽:766
半短發發型圖片男 瀏覽:951
飛機頭的圖片的怎麼弄啊你給我弄 瀏覽:811