2012-06-29 44 views
-1

我有在通过点击另一个里所存在另一页上除去锂的问题点击另一个立..和除去锂的id除去锂存在于localStorage的可变..通过使用jquery和JavaScript

这里有两个div出现在同一页面上。 第一李代码是

<div data-role="page" id="wishListPage" data-add-back-btn="true"> 
      <div data-role="header" data-position="fixed"> 
       <header id="mainHeader" align="center"> 
        <a href="#"><img src="images/logoName.png" /> </a> 
       </header> 
      </div> 
      <div data-role="content" data-theme="a" id="wishProducts"> 
       <ul id="wishList" data-role="listview"></ul> 
      </div> 
    </div> 

立设置,其值是从DATABSE rs.rows.item(i).id

$("#wishList").append('<li id="'+rs.rows.item(i).id+'"><a href="index.html#removeProductDialogPage" data-role="button" data-rel="dialog" data-transition="slide" data-ajax="false" onClick=saveValuesInLocalStorage("'+rs.rows.item(i).id+'","'+rs.rows.item(i).productName+'","'+rs.rows.item(i).imageName+'","'+rs.rows.item(i).vendorImageName+'","'+rs.rows.item(i).fixedPrice+'","'+rs.rows.item(i).finalPrice+'","'+rs.rows.item(i).authorName+'","'+rs.rows.item(i).sharingUrl+'");>' + 
       '<img src='+rs.rows.item(i).imageName+' id="itemImage"/>'+ 
       '<span id="dataName"><h4>'+pName+'</h4></span>' + 
       '<p><span id="dataAuthorName">'+aName+'</span></p>' + 
       '<p><span id="itemRsPrice">Rs.&nbsp;&nbsp;</span><span id="itemStrikePrice"><strike>'+rs.rows.item(i).fixedPrice+'</strike></span>&nbsp;&nbsp;<span id="itemPrice">'+rs.rows.item(i).finalPrice+'</p></span>'+'<img src='+rs.rows.item(i).vendorImageName+' id="itemSite"/></a></li>'); 
     } 
     $("#wishList").listview("refresh"); 

这里未来的心愿是UL的id .. ,并存储在localStorage的代码的属性..

function saveValuesInLocalStorage(productUrl, productName , productImageName , vendorImage , fixedPrice, finalPrice, authorName,sharingUrl){ 
    localStorage.sharingUrl = sharingUrl; 
    localStorage.productUrl = productUrl; 
    localStorage.productName = productName; 
    localStorage.imageName = productImageName; 
    localStorage.vendorImage = vendorImage; 
    localStorage.fixedPrice = fixedPrice; 
    localStorage.finalPrice = finalPrice; 
    localStorage.authorName = authorName; 
} 

现在我想删除ID为的那个li localStorage.productUrl

和对话页面:

<div data-role="content" data-theme="a"> 
      <ul name="options" id="options" data-role="listview"> 
       <li> 
        <a href="#" data-theme="a" data-ajax="false" onClick=" removeInfoDatabase()"> 
         <p><span id="itemName"><h4>Remove from wish List</h4></span></p> 
        </a> 
       </li> 
       <li> 
        <a href="javascript:void(0);" data-theme="a" data-ajax="false" onclick="openWebLink()"> 
         <p><span id="itemName"><h4>Go to Store</h4></span></p> 
        </a> 
       </li> 
      </ul> 
</div> 

下面的代码是显示了PhoneGap的SQLite的代码。 和removeInfoDatabase()函数是..

function removeInfoDatabase(){ 
    db.transaction(removeElement, removeError, removeSuccess); 
} 

function removeError(err){ 
    console.log("Error processing SQL: "+err.code); 
    alert("couldn't remove from wish list"); 
} 
function removeSuccess(){ 
    var elem =document.getElementById(localStorage.productUrl); 
    elem.parentNode.removeChild(elem); 
// $("#"+localStorage.producturl).remove(); 
// var mm = $("#"+localStorage.producturl).html(); 
// alert(""+mm); 
    $("#wishList").listview("refresh"); 
    alert("item is removed successfully"); 
    history.back(); 
} 
function removeElement(tx){ 
    tx.executeSql('CREATE TABLE IF NOT EXISTS itemDetail (id unique, productName , imageName, vendorImageName , fixedPrice , finalPrice , authorName , sharingUrl)'); 
    tx.executeSql('DELETE from itemDetail where id="'+localStorage.productUrl+'"'); 
} 

现在我怎么CAL删除点击删除愿望清单里 请帮我之后心愿列表里..请 在此先感谢..

+4

对此我们无能为力。提供详细信息,代码示例和测试用例。 –

+0

这两个页面在同一个网站上? – Alnitak

+0

@BramVanroy当然我们可以用这个做点什么! – Alnitak

回答

1

假设这两个页面在同一个站点上(因此它们共享相同的localStorage对象),最容易的选择是在将删除该元素的页面上使用setTimeout()来轮询本地存储以查找ID的存在。

function pollStorage() { 
    var id = localStorage.id; 
    if (typeof id !== 'undefined') { 
     delete localStorage.id; 
     $(id).remove(); 
    } 
    setTimeout(pollStorage, 100); 
} 

pollStorage();