我使用此代碼來改變形象src屬性數據src屬性,但它不工作,我不知道我做錯了任何幫助將是appreciated.Thanks如何在javascript中將img src屬性更改爲data-src?
<script>
$("img").each(function() {
$(this).attr("data-src",$(this).attr("src"));
$(this).removeAttr("src");
});
</script>
<img src="test.jpg" width="300" height="200">
我想這個輸出
<img data-src="test.jpg" width="300" height="200">
此代碼應該工作的罰款。你確定'data-src' attr沒有出現在DOM中嗎?檢查元素。 – Utkanos
你最好描述預期的結果。描述看起來很奇怪 – Anarion
Javcascript代碼是否在'$(document).ready()'內? – Barmar