小编Dav*_*ion的帖子

用循环显示卡引导程序中的每个 json 数据

大家好,我在这里有点困惑。我有一个关于如何循环此代码的问题,因此最终结果将是卡内独立显示的每个数据(每个数据与https://jsonplaceholder中的 url 具有不同的 id) .typicode.com/posts)。这是代码:

html

<div class="container">
    <div class="card bg-warning">
        <!-- put item.userId & item.id below this -->
        <div class="card-header"></div>

        <div class="card-body">
            <!-- put item.title below this -->
            <h5 class="card-title"></h5>
            <!-- put item.body below this -->
            <p class="card-text"></p>
        </div>
    </div>
</div>
Run Code Online (Sandbox Code Playgroud)

js

    $(function () {
        $.ajax({
            url: "https://jsonplaceholder.typicode.com/posts",
            success: function (result) {
                $.each(result, function (index, item) {
                    var userId = item.userId;
                    var typeId = item.id;
                    var titleId = item.title;
                    var bodyId = item.body;
                    var $head = $(".card-header").html("user …
Run Code Online (Sandbox Code Playgroud)

html javascript ajax jquery loops

1
推荐指数
1
解决办法
5712
查看次数

标签 统计

ajax ×1

html ×1

javascript ×1

jquery ×1

loops ×1