实现王者荣耀的局内道具的详细显示列表

本文通过布局、导入jQuery和JSON数据,详细介绍了如何实现王者荣耀游戏内的道具详细显示列表。首先进行CSS布局,然后利用jQuery获取并解析从官网爬取的JSON文件,根据item_id动态加载道具图片,并根据道具类型进行区分。最后展示了实现的效果。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >


前言

使用jQuery和html,css来实现王者荣耀的局内道具的详细显示列表。


一、先布局,完成css部分

设置了一个按钮,点击就获取所有的装备数据
图片地址是在王者荣耀官网找的。
"https://game.gtimg.cn/images/yxzj/img201606/itemimg/1111.jpg

<style>
        .tab{
            margin:0 auto;
            width: 1200px;
            border:1px solid rgba(52,52,52,0.5);
            border-collapse: collapse;
        }
        .tab th{
            padding:10px 20px;
            height: 30px;
            background: #2c3e50;
            color:#eee;
        }
        td{
            padding:10px 20px;
            border:1px solid rgba(52,52,52,0.5);
        }
        td img{
            width: 87px;
            height: 87px;
        }
    </style>
</head>
<body>

<button>获取装备数据</button>
<table class="tab">
    <thead>
    <tr>
        <th>编号</th>
        <th>图片</th>
        <th>装备名</th>
        <th>装备类型</th>
        <th>售价</th>
        <th>总价</th>
        <th>属性</th>

    </tr>
    </thead>
    <tbody>
    <tr>
        <td>1111</td>
        <td><img src="https://game.gtimg.cn/images/yxzj/img201606/itemimg/1111.jpg"></td>
        <td>铁剑</td>
        <td>攻击</td>
        <td>150</td>
        <td>250</td>
        <td><p>+20物理攻击</p></td>
    </tr>
    </tbody>
</table>

在这里插入图片描述

二、导入jQuery,json文件并获取

json文件是在王者荣耀官网爬的,就是这种文件。
在这里插入图片描述

三、完成script部分

json文件里面一个名字对应一个数据,那个图片地址很容易看出来后缀就是item_id,一个id对应一个图片https://game.gtimg.cn/images/yxzj/img201606/itemimg/${e.item_id}.jpg,这就可以找到所有的图片。最后还要判断一个装备的类型,不同的数字对应不同的类型,比如1对应攻击。

<script src="../js/jquery-1.11.3.js"></script>
<script>
    $(function () {
        $('button').click(function () {
            $.getJSON("../json/局内道具_item.json",function (data) {
                renderData(data);
            })
        })

    function renderData(data) {
        let html = '';
        $(data).each(function (i,e) {
            html +=`<tr>
                        <td>${e.item_id}</td>
                        <td><img src="https://game.gtimg.cn/images/yxzj/img201606/itemimg/${e.item_id}.jpg"></td>
                        <td>${e.item_name}</td>
                        <td>${typeFmt(e.item_type)}&nbsp;${e.hero_type2 ? typeFmt(e.item_type2) : ""}</td>
                        <td>${e.price}</td>
                        <td>${e.total_price}</td>
                        <td>${e.des1}${e.des2}</td>

                        </tr>`
        })
        $('.tab tbody').html(html);
    }

    function typeFmt(type){
        switch(type){
            case 1:
                return "攻击";
            case 2:
                return "法术";
            case 3:
                return "防御";
            case 4:
                return "移动";
            case 5:
                return "打野";
            case 6:
                return "游走";
            default:
                return null;
        }
    }



    })
</script>

四、效果展示

在这里插入图片描述

总结

jQuery可以让我们做到打最少的代码,做最多的事。

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值