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
473 views
in Technique[技术] by (71.8m points)

javascript - 记住浏览器后退按钮上最后选择的单选按钮(Remember lastly selected radio button on the browser-back button)

I got three radio buttons.(我有三个单选按钮。)

I want the browser to remember the last selected/checked radio button, while I use to navigate through the browser back button .(我希望浏览器记住上一个选中/选中的单选按钮,而我却使用它来浏览浏览器的后退按钮 。) I have already stored the values in the local storage .(我已经将值存储在本地存储中 。) The problem and flow,(问题和流程,) Page A has a radio button (where I have selected 2nd radio button)(网页A有一个单选按钮(我在其中选择了第二个单选按钮)) Now I go to another page B(现在我去另一页B) Lastly, I jump back to page A using browser back button(最后,我使用浏览器后退按钮跳回到A页) Get the result that the 1st radio button is selected(得到选择第一个单选按钮的结果) Want solution on this : How can I dynamically set something to remember the last click event on the radio buttons?(需要以下解决方案 :如何动态设置一些功能以记住单选按钮上的最后单击事件?) HTML(的HTML) <div class="row mb-3"> <div class="col-10 form-inline justify-content-xl-center"> <div class="form-check form-check-inline"> <input class="form-check-input" type="radio" name="filterClient" id="filterClientes1" value="activeClient" checked="checked" (change)="statusCustomers = '1'"> <label class="form-check-label" for="filterClient1" i18n="Filter | Customers filter.@@filter_actives"> <b>Active Customers</b> </label> </div> <div class="form-check form-check-inline"> <input class="form-check-input" type="radio" name="filterClient" id="filterClient2" value="inactiveClient" (change)="statusCustomers = '0'"> <label class="form-check-label" for="filterClient2" i18n="Filter | Customers filter.@@filter_inactives"> <b>Inactive Customers</b> </label> </div> <div class="form-check form-check-inline"> <input class="form-check-input" type="radio" name="filterClient" id="filterClient3" value="allClient" (change)="statusCustomers = '2'"> <label class="form-check-label" for="filterClient3" i18n="Filter | Customers filter.@@filter_all"> <b>All Customers</b> </label> </div> </div> </div> TYPESCRIPT(打字稿) filterCustomer(fieldValue: string, statusCustomers: string, statusQueries: string) { // * REMOVE WHEN WE'RE DONE statusQueries = '1'; this.restartFields(); const swalWithBootstrapButtons = Swal.mixin({ customClass: { confirmButton: 'btn btn-primary', cancelButton: 'btn btn-outline-secondary ml-4' }, buttonsStyling: false }); this.filteredCustomer = []; if (fieldValue === '') { this.showspinner = false; this.searchError = 'You must enter a search'; } else { this.searchError = ''; this.showspinner = true; this.customerService.getCustomers(fieldValue, statusCustomers, statusQueries).subscribe(data => { if (data.length === 0) { this.nullError = 'No customer related search found'; } localStorage.setItem('filterField', JSON.stringify(fieldValue)); localStorage.setItem('radiobuttonsCustomers', JSON.stringify(this.statusCustomers)); data.map(item => { this.filteredCustomer.push(item); localStorage.setItem('customers', JSON.stringify(this.filteredCustomer)); }); this.showspinner = false; this.paginationDisplayed = this.filteredCustomer.length > environment.DTSize; this.initializeDT(); }, error => { swalWithBootstrapButtons.fire( 'Error!', 'Error Not Applicable.', 'error' ); }); this.customers = this.filteredCustomer; } }(})   ask by Augustine translate from so

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

1 Answer

0 votes
by (71.8m points)

You change the state of checked in such a way(您以这种方式更改已检查状态)

[checked]="variable_name" here the variable should be boolean.(这里的变量应该是布尔值。) Also write the below line in ngOnInit in lifecyle hook(同样在lifecyle钩子的ngOnInit中写下以下行) variable_name = JSON.parse(localstorage.getItem('fieldName_in_localStorage'))

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
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

56.8k users

...