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

熱點內容
男孩齊劉海發型圖片 瀏覽:798
翻白眼圖片可愛卡通 瀏覽:135
劇型女孩的圖片 瀏覽:775
長腿初中女孩圖片 瀏覽:114
手機上輸入文字圖片 瀏覽:92
干凈的清新文字圖片 瀏覽:808
動漫qq男生高清頭像大圖片 瀏覽:364
珍寶珠發型圖片 瀏覽:93
給你一個可愛的卡通圖片 瀏覽:801
ppt裡面如何設置圖片環繞方式 瀏覽:391
蘋果肌怎麼練圖片 瀏覽:271
大清紙幣圖片及價格表 瀏覽:463
美女與白馬圖片 瀏覽:373
科學手抄報簡單漂亮圖片一年級 瀏覽:709
手繪動漫女生短發頭像圖片大全 瀏覽:9
女孩牽著馬的卡通圖片 瀏覽:766
姓賈圖片文字 瀏覽:788
短發嘴角下燙頭發發型圖片 瀏覽:202
女孩淋雨圖片卡通圖片 瀏覽:617
簡單隨遇而安圖片 瀏覽:499