简体   繁体   English

重定向到其他页面并返回上一页后,已启用的按钮被禁用

[英]The enabled button is getting disabled after redirecting to other page and coming back to the previous page

I have disabled a button by default.我默认禁用了一个按钮。 When user checks a checkbox then the button is getting enabled.当用户选中一个复选框时,该按钮将被启用。 But in the same page we have some links to redirect to other pages.但是在同一页面中,我们有一些链接可以重定向到其他页面。 If we click on any link the new page is getting opened and then if we come back to the same page the button which was enabled is getting disabled though the checkbox is checked.如果我们单击任何链接,新页面将被打开,然后如果我们返回同一页面,虽然选中了复选框,但已启用的按钮将被禁用。 How can i keep the button state enabled after redirect?重定向后如何保持按钮 state 启用?

Please find the code for the page:请找到页面的代码:

function() {
 var $checkbox = this.$checkbox[0]
 if $checkbox.checked {
  this.$button.prop("disabled", false);
 }
 else {
  this.$button.prop("disabled", true)
 }
}

The nature of Javascript variables is to live within the life of a page view. Javascript 变量的本质是存在于页面视图的生命周期内。 If you change between documents, the variable states get lost.如果您在文档之间进行更改,变量状态就会丢失。 So you could just consider leveraging the local storage.所以你可以考虑利用本地存储。

localStorage.setItem('myCat', 'Misu');

Please read the docs in details, I think this could be the base of what you're looking for.请详细阅读文档,我认为这可能是您正在寻找的基础。 https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage https://developer.mozilla.org/zh-CN/docs/Web/API/Window/localStorage

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM