我有一个带有列表视图的应用程序(jQuery mobile 1.4.3),我正在用AJAX动态加载列表。
我正在使用相同的列表视图加载2种不同类型的Ajax数据,我需要删除/更改CSS,以便在单击/加载按钮2222时按钮和左侧空间消失。

jsfiddle:JSFIDDLE (CLICK the button 2222 to show list)

一些示例代码:

function func1111() {
    var $menuList = $("#suggestions-list");

    $menuList.empty();

    var listItem = document.createElement("li");
    var divForButtons = document.createElement("div");
    var anchor = document.createElement("a");
    var buttonAdd = document.createElement("a");
    var buttonDelete = document.createElement("a");
    var header1 = document.createElement("h1");
    var header = document.createElement("h3");
    var paragraph = document.createElement("p");

    anchor.setAttribute("href", "");
    anchor.setAttribute("data-id", "hey");

    header.textContent = "something";
    header1.textContent = "hello";
    paragraph.textContent = "10" + "€";

    buttonAdd.setAttribute("href", "#");
    buttonAdd.setAttribute("id", "btnUserSugAdd");
    buttonAdd.setAttribute("data-id", "1");
    buttonAdd.setAttribute("class", "ui-btn ui-icon-plus ui-btn-icon-notext ui-corner-all");

    buttonDelete.setAttribute("href", "#");
    buttonDelete.setAttribute("id", "btnUserSugDel");
    buttonDelete.setAttribute("data-id", "2");
    buttonDelete.setAttribute("class", "ui-btn ui-icon-delete ui-btn-icon-notext ui-corner-all");

    divForButtons.setAttribute("class", "editBtns");
    divForButtons.appendChild(buttonAdd);
    divForButtons.appendChild(buttonDelete);

    anchor.appendChild(header);
    anchor.appendChild(header1);
    anchor.appendChild(paragraph);

    listItem.appendChild(anchor);
    listItem.appendChild(divForButtons);

    $menuList.append(listItem);


    $menuList.listview('refresh');

}


我希望我不要对我的问题感到困惑,在此先感谢。

最佳答案

在一个函数中,将类has-editBtns添加到UL中,在另一个函数中将其删除:

function func1111() {
    var $menuList = $("#suggestions-list");
    $menuList.empty().addClass('has-editBtns');
    ...

function func2222() {
    var $menuList = $("#suggestions-list");
    $menuList.empty().removeClass('has-editBtns');
    ...



  更新了FIDDLE

10-04 22:11