2014-09-02 138 views
0

我有一個應用程序(jQuery手機1.4.3)與列表視圖,我用AJAX動態加載列表。 我使用相同的列表視圖加載2種不同類型的ajax數據,我需要的是刪除/更改css,以便按鈕和左側空間在點擊/加載按鈕2222時消失。更改css相同的列表視圖

的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'); 

} 

我希望我was't我的問題太混亂了,在此先感謝。

回答

1

在一個函數中添加類有-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