游.程 2012-08-27 16:57 采纳率: 0%
浏览 28

加载AJAX时缺少CSS [重复]

This question already has answers here:
                </div>
            </div>
            <div class="grid--cell mb0 mt8">Closed <span title="2012-08-27 23:12:19Z" class="relativetime">7 years ago</span>.</div>
        </div>
    </aside>

Possible Duplicate:
jQuery Mobile styles for an asynchronously included div
Jquery mobile listview - check initialization is complete

I have a mobile jquery list view and there is a LOAD MORE BUTTON at the end. Everything works fine except that the css is missing on the new results added using AJAX.

Here is my Button code

<div data-role="fieldcontain">
            <a onclick="loadmore(this);" type="button" id="showmore" href="#more">Load more..</a>
        </div>

Javascript

function loadmore(a) {
    jq("#show_more_btn").removeClass("show_more_btn");
    jq("#show_more_btn").addClass("loading_btn");
    jq("this").css("display", "none");
    if (null == jq.cookie("bp-activity-oldestpage")) jq.cookie("bp-activity-oldestpage", 1, {
        path: "/"
    });
    var b = jq.cookie("bp-activity-oldestpage") * 1 + 1;
    jq.post(ajaxurl, {
        action: "activity_get_older_updates",
        cookie: encodeURIComponent(document.cookie),
        page: b
    }, function (a) {
        jq("#show_more_btn").removeClass("loading_btn");
        jq("#show_more_btn").addClass("show_more_btn");
        jq.cookie("bp-activity-oldestpage", b, {
            path: "/"
        });
        jq("li[class='load-more']").hide();
        jq("#activity-stream").append(a.contents);
    }, "json");
    return false
}

Screenshot of correct listview http://s12.postimage.org/yd2hsk119/original.jpg

Problem http://s17.postimage.org/81ofaf1bz/got.jpg

EDIT: Listview code

<div class="content-primary">   
            <ul data-role="listview"  id="activity-stream">
    <?php endif; ?>

    <?php while ( bp_activities() ) : bp_the_activity(); ?>

        <?php locate_template( array( 'activity/entry.php' ), true, false ); ?>

    <?php endwhile; ?>

    <?php  if ( empty( $_POST['page'] ) ) :  ?>

            </ul>
        </div>

Entry.php

<li id="activity-<?php bp_activity_id(); ?>">
<a href...>...</a>
<h3>...</h3>
<p>...</p>
</li>

Anyone knows what the problem is ?

</div>
  • 写回答

1条回答 默认 最新

  • weixin_33691817 2012-08-27 17:02
    关注

    You need to refresh the listview like this:

    $("ul").listview('refresh');
    

    You are adding the elements to the list but they are not styled by jQuery mobile since they do not have the proper classes and attributes.

    评论

报告相同问题?

悬赏问题

  • ¥15 学不会递归,理解不了汉诺塔参数变化
  • ¥15 基于图神经网络的COVID-19药物筛选研究
  • ¥30 软件自定义无线电该怎样使用
  • ¥15 R语言mediation包做中介分析,直接效应和间接效应都很小,为什么?
  • ¥15 Jenkins+k8s部署slave节点offline
  • ¥15 如何实现从tello无人机上获取实时传输的视频流,然后将获取的视频通过yolov5进行检测
  • ¥15 WPF使用Canvas绘制矢量图问题
  • ¥15 用三极管设计一个单管共射放大电路
  • ¥15 孟德尔随机化r语言运行问题
  • ¥15 pyinstaller编译的时候出现No module named 'imp'