5 回答

TA貢獻1963條經(jīng)驗 獲得超6個贊
從你的截圖來看,新圖來自 windows 本地路徑(如 file:///d:\b.png)。
出于安全考慮,瀏覽器會禁止非 file:// 來源的網(wǎng)頁訪問,要不然,你瀏覽的任何網(wǎng)頁都可以隨意訪問你的本地磁盤文件。
也就是說,當你用 file://xxx.html 打開網(wǎng)頁時,可以訪問同類的 file://... 或 http://...(含 https,下同)的資源。
若用 http://... 打開網(wǎng)頁時,則不能訪問 file://... 的資源。
以下是測試例子
<html>
<head>
<script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
<script>
$(function() {
$("img").click(function(e) {
// 改成本地路徑可能無法顯示
this.src = "d:\b.png";
// 改成遠端路徑可以
// this.src = "https://www.baidu.com/img/bd_logo1.png";
});
});
</script>
</head>
<body>
<img src="a.png" />
</body>
</html>
添加回答
舉報