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

熱點內容
怎麼把word的柱狀圖變成圖片 瀏覽:753
動漫森女圖片 瀏覽:404
漢服圖片衣服紙樣 瀏覽:749
最美女殺手安娜圖片 瀏覽:746
ppt如何讓圖片背景去掉 瀏覽:737
披發發型圖片優雅 瀏覽:383
word組合圖形和圖片 瀏覽:602
男生專用聊天背景圖片黑色 瀏覽:473
織語毛巾價格圖片 瀏覽:822
漂亮可愛寶可夢圖片 瀏覽:923
小女孩高冷圖片 瀏覽:788
絨線鉤衣服的花樣圖片 瀏覽:949
張敬軒發型圖片 瀏覽:662
word在表格中插入圖片如何布滿 瀏覽:663
短臉蛋發型圖片 瀏覽:855
土酒價格圖片 瀏覽:768
純色簡約黑衣服圖片 瀏覽:628
人心不簡單圖片大全 瀏覽:814
想你了男生圖片動漫 瀏覽:133
臉長男適合的發型圖片 瀏覽:941