ユーザーがボタンをクリックしてアイテムを選択するWebページを作成しています。選択したアイテムの詳細がドロップボックスに表示されます。現時点では、ユーザーが再度選択した場合に数量を更新することができます。私が抱えている問題は、ユーザーが最初に btnBuy1 (ドロップボックスに表示される詳細) をクリックし、次に btnBuy2 をクリックすると (再び詳細が表示されます)、btnBuy2 をもう一度クリックすると、btnBuy2 の詳細が更新されますが、 btnBuy1 からの詳細は消えます。
$("#btnBuy0").click(function()
{
if (!sessionStorage['quantity0'])
{
sessionStorage['quantity0'] = 1;
$("#dropbox").append('<span id = "0"><img class = "thumb" src="../images/21_metoyou.jpg" />' + teddy[0].desc + ", Price £"
+ teddy[0].price + ", Quantity: " + sessionStorage.getItem('quantity0') + "</span><br/>");
}
else
{
sessionStorage['quantity0']++;
$("#dropbox").html('<span id = "0"><img class = "thumb" src="../images/21_metoyou.jpg" />' + teddy[0].desc + ", Price £"
+ teddy[0].price + ", Quantity: " + sessionStorage.getItem('quantity0') + "</span><br/>");
}
if (Modernizr.sessionstorage)
{ // check if the browser supports sessionStorage
myids.push(teddy[0].partnum); // add the current username to the myids array
sessionStorage["ids"]=JSON.stringify(myids); // convert it to a string and put into sessionStorage
}
else
{
// use cookies instead of sessionStorage
}
});
$("#btnBuy1").click(function()
{
if (!sessionStorage['quantity1'])
{
sessionStorage['quantity1']=1;
$("#dropbox").append('<span id = "1"><img class = "thumb" src="../images/birthday_metoyou.jpg" />' + teddy[1].desc + ", Price £"
+ teddy[1].price + ", Quantity: " + sessionStorage.getItem('quantity1') + "</span><br/>");
}
else
{
sessionStorage['quantity1']++;
$("#dropbox").html('<span id = "1"><img class = "thumb" src="../images/birthday_metoyou.jpg" />' + teddy[1].desc + ", Price £"
+ teddy[1].price + ", Quantity: " + sessionStorage.getItem('quantity1') + "</span><br/>");
}
if (Modernizr.sessionstorage)
{ // check if the browser supports sessionStorage
myids.push(teddy[1].partnum); // add the current username to the myids array
sessionStorage["ids"]=JSON.stringify(myids); // convert it to a string and put into sessionStorage
}
else
{
// use cookies instead of sessionStorage
}
});