简体   繁体   English

重新选择使用Chrome后退/前进的选择框?

[英]Reselect Select box on back / forward with Chrome?

I have a select box which changes the form below via ajax. 我有一个选择框,它通过ajax更改下面的表单。 If someone changes the form, clicks the back button then clicks the forward button the form changes are reset but the select box still shows the same value. 如果有人更改了表单,请单击“后退”按钮,然后单击“前进”按钮,将重置表单更改,但选择框仍显示相同的值。

How do I either do a hard page refresh or make the select box retain its default selected value? 如何刷新硬页或使选择框保留其默认selected值?

You probably have an onchange event handler on your select element. 您的select元素上可能有一个onchange事件处理程序。 Trigger that same event handler onload (or on document ready) of the document. 在文档onload (或在文档就绪时)触发相同的事件处理程序。

Reset the select box based on the value in the address bar. 根据地址栏中的值重置选择框。

Just reset the state of the check box every time the desired address is in the address bar. 每次在地址栏中输入所需的地址时,只需重置复选框的状态即可。

After detecting a change in the browser's address, you can use some simple jQuery for example: 在检测到浏览器地址的更改后,您可以使用一些简单的jQuery例如:

if (address === 'foobar.com/whatever') {
    $('input[name=foo]').attr('checked', false);
}

The above code will simply uncheck the checkbox if it's checked. 上面的代码将简单地取消选中该复选框(如果已选中)。 Do this check as soon as you detect that you are back at the address you are referring to. 一旦发现您回到了您所指的地址,请立即执行此检查。

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

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