社区所有版块导航
Python
python开源   Django   Python   DjangoApp   pycharm  
DATA
docker   Elasticsearch  
aigc
aigc   chatgpt  
WEB开发
linux   MongoDB   Redis   DATABASE   NGINX   其他Web框架   web工具   zookeeper   tornado   NoSql   Bootstrap   js   peewee   Git   bottle   IE   MQ   Jquery  
机器学习
机器学习算法  
Python88.com
反馈   公告   社区推广  
产品
短视频  
印度
印度  
Py学习  »  ArjhanToteck  »  全部回复
回复总数  1
4 年前
回复了 ArjhanToteck 创建的主题 » 如何获得数据的价值?*jquery

这适用于香草JavaScript:

<img src="lazy.png" data-kjkjsdfkjf="realurl.png">
<img src="lazy.png" data-3a4244454a="realurl.png">
<img src="lazy.png" data-32423fasf="realurl.png">
<img src="lazy.png" data-dasflkj="realurl.png">

<script>
    // gets all images in document (you can do this with only a specific div instead of document if needed)
    let images = document.getElementsByTagName("img");

    // loops through images
    for(let i = 0; i < images.length; i++){
        // the current image in the loop
        let image = images[i];

        // gets the name of the first property in the dataset
        let dataName = Object.keys(image.dataset)[0];

        // gets actual value in dataset from the name we found above
        let realUrl = image.dataset[dataName];

        // sets the new src
        image.src = realUrl;
    }
</script>