Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
325 views
in Technique[技术] by (71.8m points)

javascript - 设计中使用优惠券代码vale的流程 <p> 标记并存储在javascript中的存储中(The flow of getting a coupon code vale designed in <p> tag and stored in Storage in javascript)

Up to now I have a flow of using the Session Storage and I cant stored the data into Session Storage.(到目前为止,我已有使用会话存储的流程,并且无法将数据存储到会话存储中。)

When users received the coupon from front end with(当用户从前端收到优惠券时) <p id="coupons">No. XXXXX </p> And I want to get the value XXXXX and stored into Session Storage so that when users wants to received another coupon code (which is generated randomly), they cant received because they already have the coupons stored in Session Storage with var check = 1. Details as below(我想获取值XXXXX并存储到会话存储中,以便当用户希望接收另一个优惠券代码(随机生成)时,由于他们已经将其优惠券存储在会话存储中,并且使用var check = 1,因此无法接收。如下) var coupons = document.getElementById("coupons"); sessionStorage.setItem("flat" , 0); if(typeof(Storage) !== "undefined" || typeof(Storage) !== 0){ sessionStorage.setItem("flat", 1); sessionStorage.coupons = coupons.value; sessionStorage.setItem("coupon", sessionStorage.coupons); } else { console.log("Already received the coupon"); } When I checked on browser and it is just only flat = 1, I dont see the value XXXXX that I want to stored.(当我在浏览器上检查时,它仅是flat = 1,我没有看到要存储的值XXXXX。) And I cant check the flat = 1 when refresh the browser to get the "Already received the coupon".(而且,当刷新浏览器以获取“已收到优惠券”时,我无法检查Flat = 1。) Is there anything wrong in this case, please help.(在这种情况下有什么问题,请帮忙。) Thank you(谢谢)   ask by Huy Nguyen translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

To check if your sessionStorage contains coupon or not, you need to READ value from it by(要检查sessionStorage是否包含优惠券,您需要从中读取值)

sessionStorage.getItem('flat'); to save value use(节省价值) sessionStorage.setItem('flat', coupons.innerText )

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...