Select menu not being restored when Back button used

后端 未结 6 833
予麋鹿
予麋鹿 2021-01-31 19:47

Consider a web page that has a select menu with a JavaScript event handler tied to the menu\'s onchange event that when fired reloads the page with a new query string (using the

6条回答
  •  囚心锁ツ
    2021-01-31 20:08

    Here is a vanilla JS version of @Mitch's answer.

    let selects = document.getElementsByTagName('select');
    
    for (let i = 0; i < selects.length; ++i) {
        let currentSelect = selects[i];
        let selectedOption = currentSelect.querySelector('option[selected]');
        if (selectedOption) currentSelect.value = selectedOption.value;
    }
    

    Here is the performance comparison

提交回复
热议问题